Skip to content

Examples

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.

By goal

To build Start with Then read
A first sandbox Quickstart base, shell-exec
An isolated test runner A task on a project app-tasks, app-host-paths
An AI code reviewer Stream agent events app-agent
A patch from a coding agent Working with repositories shell-clone, app-host-paths
Agents run concurrently Run agents concurrently
A custom environment Kits and mixins shell-forge, agent-kit-forge
A restricted agent runner Restrict network access, the security checklist shell-network, shell-policy
An application tested without a daemon Testing testing-fake-daemon

Reading and running an example

From a checkout of the repository:

just example base
just example shell-exec
just example agent-claude

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 basics

Example Shows
base Connect, list sandboxes and images, create a sandbox of the shell kit, run a command, delete it
daemon A client configured before it connects; health, settings, log levels, disk usage, diagnostics; CPU and memory limits and VM metrics
images The images of the daemon: list, pull with progress, inspect, an unknown image

Shell sandboxes

Example Shows
shell-lifecycle 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
shell-exec Commands: outputs and exit codes, check, users, working directory, environment, deadlines, standard input
shell-files Files, executable scripts, whole directories in both directions, tar archives
shell-network The network policy of one sandbox: denied hosts, HTTP rules, checks, activity log
shell-policy 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
shell-ports A web server in the sandbox, published on a port of the host
shell-secrets 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
shell-ssh SSH through the socket, with the tunnel of the library relayed to the SSH client of the system
shell-clone Clone mode: the sandbox works on a private clone, the host fetches its commits
shell-templates A sandbox saved as an image, started again, exported chunk by chunk and loaded back
shell-kits A YAML mixin compiled by the sbx CLI, added to running sandboxes in place and by a container swap
shell-forge 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
shell-interactive An interactive shell relayed to the local terminal, resizing included
shell-events The event stream: the replay of recent state, then live events

MCP

Example Shows
mcp-gateway A local MCP server loaded into the gateway of a sandbox, called from inside
mcp-remote A remote server behind a bearer token the gateway injects
mcp-static A sandbox created with a static set of MCP servers
mcp-dynamic The tools of the gateway itself: find, add and call a server from inside

Coding agents

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 Review Issue over MCP Fix
Claude Code agent-claude agent-claude-mcp agent-claude-automation
Codex agent-codex agent-codex-mcp agent-codex-automation
GitHub Copilot agent-copilot agent-copilot-mcp agent-copilot-automation
Cursor agent-cursor agent-cursor-mcp agent-cursor-automation
Devin agent-devin agent-devin-mcp agent-devin-automation
Docker Agent agent-docker-agent agent-docker-agent-mcp agent-docker-agent-automation
Droid agent-droid agent-droid-mcp agent-droid-automation
Kiro agent-kiro agent-kiro-mcp agent-kiro-automation
OpenCode agent-opencode agent-opencode-mcp agent-opencode-automation

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.

Kits and sandbox specs

Example Shows
kit-cache 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)
blueprint-json 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)

Testing

Example Shows
testing-fake-daemon 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

Applications

Example Shows
app-tasks 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:
app-host-paths 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
app-dependencies 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
app-agent 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
app-cli The fastsandbox command line on an application found by its path: tasks, run with its options, info