The repository holds one tutorial per file under
examples/:
each example shows one use of the library from the connection to the cleanup,
every call to the library in plain sight. The examples of the client follow
those of docker-sandbox,
under the same names; the parts that are Python alone have their own: kits and
sandbox specs, the fake daemon, and FastSandbox applications. Where the
snippets of this documentation show one thing at a time, an example runs a
whole use end to end, and checks what it does.
An example reads from top to bottom: its docstring says what it shows, what
was measured on a real daemon, the credentials it reads, and how to run it;
its main follows in numbered steps, whose comments say what each call does
and why. Code that several examples need is written in each of them, so that
every example reads on its own. Its entry point is fastsandbox.run(main()):
Ctrl+C cancels it and the async with blocks remove what it created, a
failure ends with its traceback, and a check that does not hold exits with
error: ….
Every example but testing-fake-daemon talks to the daemon of the current
user, creates the sandboxes it needs and deletes them when it ends: run them
as the user owning the daemon. Kits come from the
kit cache of the client
(client.package), which forges them without the sbx CLI. The CLI is
needed by shell-kits, kit-cache --compile, agent-kit-args, which
compiles its kit with it, the MCP examples and the -mcp variants, which
register MCP servers with it; a terminal by
shell-interactive and the interactive agents; a credential by the agents run
unattended. What an example writes on the host stays under
examples/target/, which Git ignores. The
README of the examples
describes each of them in full.
The life of a sandbox: streamed creation, a failed creation read from its line, typed errors, sessions, start and stop, ports, working directory, guarded deletion
The global policy: rules added, checked and removed, hosts a rule cannot name refused with their reason (HostPattern) and before they are sent, host path permissions, approval prompts
Custom secrets, one held as a SecretStr, a proxied key and service credentials pushed through the socket, injected by the proxy; the answer of the daemon, and the credentials it withholds
A package forged without the sbx CLI, with a mixin written in Python and one read from its directory; kits named as the CLI takes them (KitRef); what the forge refuses; the package assembled by hand from its request and its images; the package saved, opened again, and its base kit composed again
Three examples per agent sbx knows, each a task a program gives an agent,
without a terminal, on one small project, a calculator whose sub adds:
review: the agent reviews the code and writes its findings to a file,
which the program reads back as Python data and checks;
-mcp: the agent triages an issue of a tracker served on the host over
MCP, loaded into the gateway of its sandbox: it reads the issue, finds its
cause in the code, and comments on the issue through the tool, where the
program reads the comment;
-automation: the agent fixes the bug in a project mounted from the host,
and the tests decide.
Each runs its agent with
AgentRunner.prompt, the
command of Agent.headless,
and gives the key of its agent, read from the environment, to the proxy of its
sandbox alone, as a proxied key;
Kiro, whose key sbx knows no service for, gets it as is.
agent-kit-args chooses the model and the effort of the
claude kit when the sbx CLI compiles it (KitCache(sbx="sbx"),
Kit(args=…)), without starting the agent.
agent-kit-forge forges the same kit into a directory and
gives Claude Code MCP servers by a mixin
(Mixin.mcp): one of the host, reached from the sandbox
with its own token, a remote one and a stdio one.
blueprint runs the task of the unattended agents from a
sandbox spec launched in one call: the claude kit,
the project as workspace and its copy read-only, a tool of the host with the
token the launch draws, a network refusal, the keys of the agent read from the
environment; the work checked without trusting the agent, and the report of
the launch.
The kits end to end: names and checks before any pull, a KitCache in memory then in a directory with the pulls of each call counted, a changed mixin, refresh, suits, packages and mixins saved and opened again, MCP servers of three kinds and Mixin.mcp, a sandbox from the cached package, a spec launched on a package held in memory (launch_package), and --compile with the sbx CLI, a mixin then forged over the compiled package (forge_over)
A sandbox spec written by another program as JSON: refusals that name their rule, check and check_keys, two sandboxes launched from one spec with one kit cache, each with its own placeholder, the report as JSON, the to_json round trip and the keys of an agent for a package (with_keys_of)
A FastSandbox application and client code tested against FakeDaemon, without Docker Sandboxes: on_exec, routes, recorded requests and state, fake_package, a PublishedKit added, the command, the proxied key and the run of an agent task, its agent played by on_exec, and what the fake does not do
An application and its tasks: options as a sandbox spec applies them, inputs and results validated from the signature, Context and Sandbox injected, a validation error before any sandbox exists, runs at once under max_concurrency, a timeout, async with app:
Host directories given to tasks: Uploaded, Mounted read-only, WorkspaceDir read-write and clone=True, results brought back with read_text, download_dir and a patch applied on the host
A lifespan and its state, Depends (plain, async, generator, nested, cached per run), the Context of a run (run_id, logs, progress, state, the lease and its report), a synchronous task
An agent task: Claude Code on the task project mounted as its workspace, the MCP tools of the examples on the host with the token of each run (ctx.mcp_token), its key through the proxy; it runs the agent for real