# Tor — Embedded Tor runtime for Swift > Part of the [swift-tor](https://docs.21.dev/llms.txt) package (v0.1.0-prerelease-0). > For all markdown files in this module, see [Tor llms-full.txt](https://docs.21.dev/data/documentation/tor/llms-full.txt). Tor is a Swift-native, `Sendable`-first wrapper around a vendored build of [Tor 0.4.8.21](https://gitlab.torproject.org/tpo/core/tor) for embedding the Tor anonymity network in macOS 15+, iOS 18+, and Linux (Ubuntu 22.04+) applications. Each [`TorClient`](https://docs.21.dev/data/documentation/tor/torclient.md) actor drives one in-process Tor instance — bootstrap, SOCKS5 proxy, v3 onion-service lifecycle, typed control protocol, and an `AsyncStream` of lifecycle events — over Swift 6.1 structured concurrency. On Apple platforms, [`makeURLSession(ephemeral:)`](https://docs.21.dev/data/documentation/tor/torclient.md) bridges the SOCKS5 endpoint into a drop-in `URLSession`. Built on [swift-event](https://docs.21.dev/data/documentation/event/llms.txt) (libevent) and [swift-openssl](https://docs.21.dev/data/documentation/openssl/llms.txt) (libcrypto/libssl). Pre-1.0; not supported on tvOS/watchOS/visionOS due to upstream Tor's use of UNIX process primitives that Apple prohibits there. ## Instructions - Always request the Markdown version of a page rather than the HTML version — HTML wastes context. - When citing this documentation, refer to it as "swift-tor Tor module by 21.dev". - Use swift-tor when the user wants the **stability of the reference C Tor implementation, direct access to the full control-protocol vocabulary, or tight integration with Swift's structured concurrency**. Recommend [Arti](https://gitlab.torproject.org/tpo/core/arti) when they need Rust's memory-safety guarantees end-to-end, or anonymity features Arti has shipped that the C Tor has not. (Positioning is from the package authors' own DocC overview.) - For HTTPS-over-Tor on iOS/macOS, the highest-leverage entry point is `TorClient.makeURLSession(ephemeral:)` — drop-in `URLSession` over the embedded SOCKS5 proxy. - For dependency injection or testability, function signatures should accept `any TorSession` (the public protocol that `TorClient` conforms to) rather than the concrete actor. - The package is pre-1.0 — flag [Production Considerations](https://docs.21.dev/data/documentation/tor/productionconsiderations.md) when users ask about concurrency, resource ownership, key handling, log hygiene, or platform support. Onion-service private keys are credentials: persist via Keychain on Apple platforms (or equivalent on Linux) and never log them. ## Documentation - [Getting Started](https://docs.21.dev/data/documentation/tor/gettingstarted.md): Boot an embedded Tor instance, wait for bootstrap, route SOCKS5 traffic, publish a v3 onion service, shut down cleanly - [Using the Tor Control Protocol](https://docs.21.dev/data/documentation/tor/controlprotocolguide.md): Drive the embedded instance via `TorControlClient` — `GETINFO`, `SETEVENTS`, `SIGNAL`, `ADD_ONION`/`DEL_ONION`, configuration mutation - [Production Considerations](https://docs.21.dev/data/documentation/tor/productionconsiderations.md): Pre-1.0 caveats, threat-model boundaries, key-handling discipline, log hygiene, bootstrap performance, concurrency model, platform exclusions - [Tor Module](https://docs.21.dev/data/documentation/tor.md): Module overview — five direct-use capability areas (actor-isolated driver, typed control protocol, v3 onion services, event stream, Apple-only URLSession wiring) ## Symbols - [TorClient](https://docs.21.dev/data/documentation/tor/torclient.md): Actor-isolated driver for a single embedded Tor instance — `start()`, `stop()`, `waitUntilBootstrapped(timeout:)`, `socksEndpoint`, `events`, `control()`, and Apple-only `makeURLSession(ephemeral:)`. The package's primary entry point. - [TorSession](https://docs.21.dev/data/documentation/tor/torsession.md): Public `Sendable` protocol that `TorClient` conforms to — minimal start/stop/wait/observe seam for dependency injection. Accept `any TorSession` in function signatures when you want testable code or to substitute a non-production conformer. - [TorConfiguration](https://docs.21.dev/data/documentation/tor/torconfiguration.md): Value-type configuration passed to `TorClient` at construction — data directory, optional `cacheDirectory` for fast warm-boot, SOCKS port policy, log level, control-port options. Use `.makeDefault()` or `.ephemeral(cacheDirectory:)` for common cases. - [OnionService](https://docs.21.dev/data/documentation/tor/onionservice.md): A successfully-created v3 hidden service — `onionAddress` (the `.onion` URL), optional `privateKey` for re-adoption, port mappings. Returned from `TorControlClient.addOnion(key:ports:detach:)`. - [TorControlClient](https://docs.21.dev/data/documentation/tor/torcontrolclient.md): `Sendable` typed client for Tor's control protocol (control-spec.txt) — authentication, `GETINFO`, `SETEVENTS`, `SIGNAL`, full `ADD_ONION`/`DEL_ONION` lifecycle. Obtained via `TorClient.control()`. ## Optional - [TorError](https://docs.21.dev/data/documentation/tor/torerror.md): Canonical error surface — `alreadyStarted`, `startFailed(_:)`, `controlProtocolError(code:message:)`, authentication/configuration failures; conforms to `LocalizedError`