fastsandbox
Docker Sandboxes for Python: a typed async client of the sandboxd socket of
Docker Sandboxes (sbx), and
FastSandbox, a declarative framework for tasks and AI coding agents that
run in throw-away sandboxes.
It is built on docker-sandbox, the
Rust client of the socket, through PyO3: every call of the library, its
streams, sessions and errors, with Pydantic models for every payload.
Documentation: https://aartintelligent.github.io/fastsandbox/
from pathlib import Path
from typing import Annotated
from pydantic import BaseModel
from fastsandbox import Context, FastSandbox, Network, Uploaded, WorkspaceDir
app = FastSandbox("ci-agents")
class Report(BaseModel):
passed: bool
summary: str
@app.task(kit="shell", network=Network.allow("pypi.org"), timeout="10m")
async def run_tests(ctx: Context, repo: Annotated[Path, Uploaded("/work")]) -> Report:
out = await ctx.sandbox.exec("cd /work && make test")
return Report(passed=out.ok, summary=out.stdout[-500:])
@app.agent("claude", timeout="20m")
async def fix_bug(ctx: Context, repo: Annotated[Path, WorkspaceDir()], issue: str) -> Report:
await ctx.agent.prompt(f"Fix this issue: {issue}")
check = await ctx.sandbox.exec("make test", working_dir=str(repo.resolve()))
return Report(passed=check.ok, summary=check.stdout[-500:])
fastsandbox run app.py fix_bug --repo . --issue "the parser drops the last line"
Each call creates a sandbox from its kit, applies its network rules, pushes the agent's credentials to that sandbox only, keeps it running while the task runs, validates the inputs and the result with Pydantic, and deletes it.
This project is not affiliated with Docker, Inc. The
sandboxdsocket API is private and changes withsbxreleases;docker-sandboxkeeps a map of it per version and checks the API version of the daemon when it connects.
Requirements
fastsandbox is a client of Docker Sandboxes: it connects to the socket of its
daemon, sandboxd, and does nothing without it. Install Docker Sandboxes first.
- Linux or macOS, with Docker Sandboxes
installed and its daemon running for the current user (
sbx version). - Python 3.14 or newer.
- To build from source: a Rust toolchain (1.88 or newer) and uv.
- The
sbxCLI onPATH, to compile kits on first use (see Kits).
Installation
Install Docker Sandboxes first (see the requirements above), then:
uv add fastsandbox # or: pip install fastsandbox
fastsandbox info # the daemon, its version, the socket
The wheels hold the native extension: nothing is compiled. To work on
fastsandbox itself, from a checkout, uv sync builds the extension and
installs the package; see CONTRIBUTING.md.
With Claude Code
The repository is also a Claude Code marketplace: its plugin teaches Claude the
whole library and adds /fastsandbox:new-project, /fastsandbox:add-task,
/fastsandbox:doctor and a reviewer of fastsandbox code.
/plugin install fastsandbox --marketplace aartintelligent/fastsandbox
The client
import fastsandbox
async def main() -> None:
client = await fastsandbox.connect() # checks health and API version
async with client.create(kit="shell") as sandbox: # deleted on exit
async with sandbox.running(): # a sandbox runs while a session is held
out = await sandbox.exec("uname -a", timeout=30)
await sandbox.write_file("/tmp/notes.txt", "hello")
await sandbox.deny_hosts("example.org") # scoped to this sandbox
session = await sandbox.attach(["bash"], tty=True, size=(120, 40))
await session.write("ls\n")
async for chunk in session: # OutputChunk(stream, data)
...
async for event in await client.events.subscribe_live():
print(event.kind, event.action, event.sandbox_name)
fastsandbox.run(main())
Every handle and method of docker-sandbox is there:
| Domain | Python |
|---|---|
| Client, socket, API version | connect(), Client.health, SUPPORTED_API, default_socket_path() |
| Daemon | client.daemon: health, info, settings, log levels, disk usage, diagnostics |
| Sandboxes | client.sandboxes: list, get, find, create, create_stream (progress) |
| Life cycle | Sandbox: inspect, start, stop, delete, save as template, working dir, host paths, VM metrics |
| Sessions | hold_session(), ensure_running(), async with sandbox.running() |
| Commands | exec (ExecOutput), exec_inspect, attach and agent_session (Interactive: stdin, output stream, resize, wait, collect) |
| Files | read, write, archives, upload_dir, download_dir |
| Ports | ports, publish, unpublish, replace the desired port |
| Network | client.policy: rules, apply, check, log, profiles; per sandbox: allow, deny, remove hosts |
| Credentials | push_credentials (CredentialsUpdate, custom secrets), service secrets |
| Kits | KitPackage, KitAgent, KitCompiler, KitCache; in-place install and container swap |
| MCP | gateway mode, registration checks, gateway of a sandbox, load and unload servers |
| Images | list, inspect, pull (with progress), load, export, remove |
| Events, prompts | client.events, client.prompts: typed async streams |
| SSH | ssh_tunnel(), a byte tunnel; fastsandbox ssh-proxy NAME as a ProxyCommand |
Payloads are Pydantic models in fastsandbox.models, in the shape of the
library: unknown fields of a newer daemon are kept. Errors derive from
fastsandbox.SandboxError: NotFoundError (with status, code,
operation), ConflictError, DaemonUnavailableError, SandboxTimeoutError,
CommandFailedError, UnsupportedVersionError…
FastSandbox
- Tasks.
@app.task(...)declares a task: its kit, network rules, timeout ("10m"), environment, CPUs and memory. Synchronousdeftasks run in a thread and reach the sandbox throughctx.wait(awaitable). - Agents.
@app.agent("claude", ...)declares a task whose sandbox runs a coding agent:claude,codex,copilot,cursor,devin,docker-agent,droid,kirooropencode. Its credentials are read from the environment (ANTHROPIC_API_KEY,OPENAI_API_KEY…) and pushed as secrets of that sandbox only: the proxy injects them, the sandbox only sees a placeholder.ctx.agent.prompt(...)runs it unattended,ctx.agent.stream(...)yields what it reports as it goes,ctx.agent.session()is interactive. - Injection by annotation.
Context,Sandbox,ClientandAgentRunnerparameters are injected, andAnnotated[T, Depends(fn)]resolves dependencies, generators included. - Host paths.
Annotated[Path, WorkspaceDir()]mounts a directory as the workspace (clone=Truefor a private Git clone),Mounted(target, read_only)mounts more,Uploaded(target)copies the contents in. - Lifespan.
FastSandbox(lifespan=...)runs around the application; what it yields isctx.state.async with app:shares one client and lifespan across runs. - Running.
await app.run("task", **inputs),app.run_sync(...),fastsandbox.run(task, **inputs), or the command line.
The command line
fastsandbox tasks app.py # tasks and their inputs
fastsandbox run app.py run_tests --repo . # inputs become options
fastsandbox run app.py:app task --input '{"repo": "."}'
fastsandbox kits compile claude # compile a kit into the cache
fastsandbox info
fastsandbox ssh-proxy my-sandbox # for ~/.ssh/config ProxyCommand
Without an application argument, fastsandbox reads [tool.fastsandbox] app
in pyproject.toml, then looks for app.py and main.py.
Kits
The daemon cannot resolve kit references by itself: a kit package captures what
the sbx CLI sends for a kit, once, and every later sandbox of that kit is
created from it through the socket alone. KitCache compiles packages on first
use into ~/.cache/fastsandbox/kits (FASTSANDBOX_KIT_CACHE overrides it) and
compiles them again when the daemon runs another sbx version. The first
compilation of an agent kit can take a few minutes.
Testing
fastsandbox.testing has a fake daemon on a Unix socket and kit packages that
need no sbx CLI, for tests that run anywhere:
from fastsandbox import FastSandbox
from fastsandbox.models import ExecOutput
from fastsandbox.testing import FakeDaemon, fake_package
async def test_run_tests(tmp_path):
async with FakeDaemon() as daemon:
daemon.on_exec(lambda sandbox, cmd: ExecOutput(exit_code=0, stdout="ok"))
app = FastSandbox(socket=str(daemon.socket_path), kit=fake_package(tmp_path / "kit"))
...
assert daemon.sandboxes == {} # deleted after the run
Interactive sessions and SSH tunnels upgrade the connection; the fake daemon does not, so code that uses them is tested against the real daemon.
Examples
examples/ holds one program per use of the library,
as the examples of docker-sandbox do, with the same names: the basics, shell
sandboxes (commands, files, network, policy, ports, secrets, SSH, clone mode,
templates, kits, interactive shells, events), the MCP gateway, and every coding
agent sbx knows, interactive, with an MCP server, or unattended on a task.
just example base
just example shell-exec
just example agent-claude ~/my-project -- "explain this project"
They talk to the daemon of the current user, create the sandboxes they need and delete them when they end, also on an error or Ctrl-C.
Security
- Whoever can reach the socket controls every sandbox; an SSH tunnel is
rootin its sandbox, without credentials. Keep both to trusted code. - The default network policy of
sbxmay allow everything: give unattended agents aNetworkand readclient.policy.log()afterwards. - Only push credentials a sandbox needs; they are scoped to it and go with it.
Development
just ci # formatting, clippy, ruff, mypy, tests, coverage, dependencies
just test # the tests, against the fake daemon
just test-live # the tests against the real daemon (creates sandboxes)
just example X # one example of examples/ (creates sandboxes)
just docs # the documentation site, previewed on http://localhost:8000
The package fastsandbox/ is at the root of the repository (the client one
module per domain of docker-sandbox, the framework one module per concept),
docs/ for the pages of the documentation site and
docs_src/ for their snippets, each tested, examples/ for the complete programs, tests/ one file per
behavior, and fastsandbox-native/ for the Rust extension. AGENTS.md details the
architecture, CONTRIBUTING.md how to contribute.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Metadata
Release files for fastsandbox 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastsandbox-0.1.1.tar.gz | 89.0 kB | With provenance | Details for fastsandbox-0.1.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| fastsandbox-0.1.1-cp314-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.14 | abi3 | Linux glibc 2.17+ x86-64 | Details for fastsandbox-0.1.1-cp314-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| fastsandbox-0.1.1-cp314-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.14 | abi3 | Linux glibc 2.17+ ARM64 | Details for fastsandbox-0.1.1-cp314-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| fastsandbox-0.1.1-cp314-abi3-macosx_11_0_arm64.whl | CPython 3.14 | abi3 | macOS 11.0+ ARM64 | Details for fastsandbox-0.1.1-cp314-abi3-macosx_11_0_arm64.whl |
| fastsandbox-0.1.1-cp314-abi3-macosx_10_12_x86_64.whl | CPython 3.14 | abi3 | macOS 10.12+ x86-64 | Details for fastsandbox-0.1.1-cp314-abi3-macosx_10_12_x86_64.whl |
Total release size: 8.1 MB
Release files / fastsandbox-0.1.1.tar.gz
| Download URL | fastsandbox-0.1.1.tar.gz |
|---|---|
| Size | 89.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9ece7063c295ffb1a4ed966d01d4700a43be2a02084c632adba455548954127
|
|
BLAKE2b-256 checksum How to use checksums |
7bf7ce2aa735ae9c4d0d570f1f626ca1aa8ad7359ed1bf2a95d4b6e6ac5864b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / fastsandbox-0.1.1-cp314-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | fastsandbox-0.1.1-cp314-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
fcb666dc0c323db9335526400ec8a9e0f6c7c5fd800e23e015044ef6dae78dfc
|
|
BLAKE2b-256 checksum How to use checksums |
2da8a542ebeb550595d557571a1826bdd99c97605a1367c14692f8199a5f9fc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / fastsandbox-0.1.1-cp314-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | fastsandbox-0.1.1-cp314-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
310f198d1d3141ff293eb8c90cd32a17afc028ad2c69feb872435650900152ec
|
|
BLAKE2b-256 checksum How to use checksums |
5b617cede9656d05a6bb476ed7bf120dadc57bdd223c8200f425e6a6849bf3e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / fastsandbox-0.1.1-cp314-abi3-macosx_11_0_arm64.whl
| Download URL | fastsandbox-0.1.1-cp314-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.14 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d01f08ff4ea1d3555dd87f8d7534fc432eee6c5a3bc8c6bc74bac4e49bc54523
|
|
BLAKE2b-256 checksum How to use checksums |
ab407c573be768e1821e5c6e01280b6db57ddc2afa1d7ddcb2480a0cd80d399f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / fastsandbox-0.1.1-cp314-abi3-macosx_10_12_x86_64.whl
| Download URL | fastsandbox-0.1.1-cp314-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.14 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
ebfee3bb994e870bdd18ba2cdfd3b1e6fd7ce1dbf40497fde8b8bb1d2af33e28
|
|
BLAKE2b-256 checksum How to use checksums |
acbec328e35dad3bd71935cc555fef2c020a560f188323c3a89ae2cc8c6161ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for fastsandbox 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for fastsandbox-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.