Skip to content

Architecture

fastsandbox is a Python package over a Rust library, which drives the daemon of Docker Sandboxes. This page shows where each part runs, which boundaries separate them, then records the decisions that shape the package, each in a few sentences, with a link to the page that shows it in use.

Where each part runs

direction: down
host: The host, as your user {
  direction: right
  program: "Your program\ntask functions,\ndependencies, lifespan"
  package: "fastsandbox\nPython package"
  native: "fastsandbox._native\nthe docker-sandbox crates"
  dirs: Host directories {shape: cylinder}
  mcphost: "MCP servers\nof the host"
  program -> package -> native
}
daemon: sandboxd and its proxy {shape: hexagon}
vm: "A sandbox: one microVM" {
  work: "Commands, programs,\ncoding agents"
}
internet: Allowed hosts {shape: cloud}
host.native -> daemon: "Unix socket,\nyour user only"
daemon -> vm: "creates, runs, removes"
vm.work -> daemon: all outbound traffic
daemon -> internet: "the network policy,\ncredentials written in"
host.dirs -> vm: a mount {style.stroke-dash: 3}
vm.work -> host.mcphost: a token {style.stroke-dash: 3}

In words: your program, fastsandbox and its native extension are one process on the host. That process talks to sandboxd through a Unix socket that only your user can open. The daemon runs each sandbox in its own microVM, and every connection a sandbox opens goes through the proxy of the daemon, which applies the network policy and writes credentials into requests.

Two boundaries matter:

  • The process boundary is the socket. fastsandbox does not isolate anything by itself: it asks the daemon, which needs no other authorization than access to the socket.
  • The trust boundary is the microVM. What runs inside it, the commands, programs and agents your code starts, is isolated by Docker Sandboxes. What runs on the host is not: the function of a task, its dependencies and its lifespan run in your process, with your user's rights.

Some paths cross the trust boundary on purpose, and only those you open: a mounted directory, shared with the host; the hosts the network policy allows; the keys the proxy writes for the sandbox; an MCP server of the host, reached with a token; a published port; an SSH tunnel. The security model goes through each of them.

Layers

grid-columns: 2
horizontal-gap: 70
vertical-gap: 60
app: "Your program\nFastSandbox tasks and agents"
python: "fastsandbox.client, .kits, .blueprint\n(Python)"
native: "fastsandbox._native\n(PyO3)"
crate: "docker-sandbox, -kit, -blueprint\n(Rust)"
daemon: "sandboxd\n(sbx daemon)" {shape: hexagon}
sandboxes: "Sandboxes\n(microVMs)" {style.multiple: true}
app -> python -> native -> crate
crate -> daemon: Unix socket
daemon -> sandboxes

The package is laid out by the crate it binds: fastsandbox.client binds docker-sandbox, the client of the socket; fastsandbox.kits binds docker-sandbox-kit, the kits and the agents sbx knows; fastsandbox.blueprint binds docker-sandbox-blueprint, the sandbox specs; fastsandbox.framework, FastSandbox, is Python alone. The names a program uses most are imported from fastsandbox itself; the others from the subpackage that holds them: the payloads from fastsandbox.models (HostPattern), the errors from fastsandbox.exceptions (KitForgeError), the fake daemon from fastsandbox.testing (FakeDaemon), and the capabilities of a mixin written in Python from fastsandbox.kits (NetworkCapability). The framework is written on the public API of the other three: each run is launched from a sandbox spec. They validate every payload with the models of fastsandbox.models and raise the errors of fastsandbox.exceptions; the native extension only bridges the Rust libraries: handles, awaitables on a shared tokio runtime, streams and errors.

Decisions

One source of truth for the daemon. Every route, field and behavior of the daemon comes from docker-sandbox, which audits the socket API version by version, and so do the rules of its kits and of a launch. A new route goes into the crates first, then here; the package never talks to the socket on its own, and never works around what the crates do not do yet.

A bridge without logic. The native extension has one frozen class per handle of the crate and turns every async method into an awaitable. Helpers, defaults and conveniences are Python, where they can be read, typed and tested.

Payloads in the shape of the crate. The models use the field names of the crate, accept the daemon's own names as aliases, and keep the fields they do not know, so that a newer daemon loses nothing on the way. See the models.

Errors classified once. The extension raises the classes of fastsandbox.exceptions, built by name from the errors of the crate, with their details as typed attributes; a program catches NotFoundError or SandboxTimeoutError without importing the extension or reading a message. See Errors.

The API version is checked. The socket API is private and changes with sbx releases. connect() compares the API version of the daemon with the range this release was checked against, and refuses one outside it unless told otherwise. See The API version.

A sandbox runs while a session is held. The daemon stops a sandbox about 30 seconds after its last session closes, so code that works in one does it inside async with sandbox.running(), and a task holds a session for its whole run. See Sessions.

Kits forged without the CLI. The daemon cannot resolve a kit by itself: a kit package holds what the sbx CLI would send for a kit, and every sandbox of that kit is created from it through the socket alone. fastsandbox reads kits as the CLI reads them, forges the package itself, the base kit rebuilt from its published image, and keeps it, in memory or in a directory, for as long as it suits the daemon; a mixin changed is made again. The CLI compiles only the kits that it alone resolves, when asked. See Kits.

A sandbox described as data. Everything a sandbox receives but its name and the values of its keys is a sandbox spec, which the crate checks and launches in one call: the kit, the mounts, the network rules, the keys, the MCP servers. The rules of a launch are those of the crate alone, and its JSON form serves a program in another language. See Sandbox specs.

The task runs on the host. The function of a task runs in the process of its caller; what runs in the sandbox is what it asks the sandbox to run. Its sandbox is launched from the spec its task and its inputs describe before the call, and removed after it, on an error or a cancellation too; only a killed process or a failed removal leaves it (see Sandbox lifecycle). See What a run does.

Keys given, never read. fastsandbox never reads the secrets stored with sbx secret set, and the daemon never gives a value back. The keys of an agent are read from the environment of the host and given to the proxy of the sandbox of the run only, which writes them in place of a placeholder; their values stay in the native extension and never come back to Python. The key of kiro, which sbx knows no service for, is the exception: it is a variable of the sandbox. See Credentials.