Skip to main content

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 sandboxd socket API is private and changes with sbx releases; docker-sandbox keeps 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 sbx CLI on PATH, 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. Synchronous def tasks run in a thread and reach the sandbox through ctx.wait(awaitable).
  • Agents. @app.agent("claude", ...) declares a task whose sandbox runs a coding agent: claude, codex, copilot, cursor, devin, docker-agent, droid, kiro or opencode. 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, Client and AgentRunner parameters are injected, and Annotated[T, Depends(fn)] resolves dependencies, generators included.
  • Host paths. Annotated[Path, WorkspaceDir()] mounts a directory as the workspace (clone=True for 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 is ctx.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 root in its sandbox, without credentials. Keep both to trusted code.
  • The default network policy of sbx may allow everything: give unattended agents a Network and read client.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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastsandbox 0.1.0
File Size Uploaded Provenance Actions
fastsandbox-0.1.0.tar.gz 89.0 kB With provenance Details for fastsandbox-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for fastsandbox 0.1.0
File Actions
fastsandbox-0.1.0-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.0-cp314-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
fastsandbox-0.1.0-cp314-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.14 abi3 Linux glibc 2.17+ ARM64 Details for fastsandbox-0.1.0-cp314-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
fastsandbox-0.1.0-cp314-abi3-macosx_11_0_arm64.whl CPython 3.14 abi3 macOS 11.0+ ARM64 Details for fastsandbox-0.1.0-cp314-abi3-macosx_11_0_arm64.whl
fastsandbox-0.1.0-cp314-abi3-macosx_10_12_x86_64.whl CPython 3.14 abi3 macOS 10.12+ x86-64 Details for fastsandbox-0.1.0-cp314-abi3-macosx_10_12_x86_64.whl

Total release size: 8.1 MB

Release files / fastsandbox-0.1.0.tar.gz

Download URL fastsandbox-0.1.0.tar.gz
Size 89.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5145f4925a86f5aac202a7bcff9d62049b4b1f9f1364b39c89b59f8ad89758d0
BLAKE2b-256 checksum
How to use checksums
dd1fc40968d2a6be0ce29feeb03964c08f305f339566db0626454b8fbd866d2c
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 log

Release files / fastsandbox-0.1.0-cp314-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL fastsandbox-0.1.0-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
77486988b1945d7ee03c3245a18e232df2baf522af1bcc048f44ce3dddc85570
BLAKE2b-256 checksum
How to use checksums
7ce95d45966a1eebcc97bf3873454c64a6e6dba4c8eea91ec9a01af6678fe034
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 log

Release files / fastsandbox-0.1.0-cp314-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL fastsandbox-0.1.0-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
aa68bb2cc94a25c5d485284f60d6472cd31385a18044e881976c312331d8767a
BLAKE2b-256 checksum
How to use checksums
41836bf557903517c0a9d60207342bb00b6d19f0d18f277cc95a816bb0977107
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 log

Release files / fastsandbox-0.1.0-cp314-abi3-macosx_11_0_arm64.whl

Download URL fastsandbox-0.1.0-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
a5821820dc4c89f01ce5d72fdb73b25e0a093ee8d583bc43b0d1d47772bfd4ee
BLAKE2b-256 checksum
How to use checksums
4753f65e432b34f0f0a8600347871591771ac71696fa6b52bbe2af4c7f0b8f78
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 log

Release files / fastsandbox-0.1.0-cp314-abi3-macosx_10_12_x86_64.whl

Download URL fastsandbox-0.1.0-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
88d69457617ba5e6a88587423a2743b2ec1a87f3821ad29a83e9a1c2bb530a05
BLAKE2b-256 checksum
How to use checksums
15fbf92bea3cc70f4060e029b259c3acbd5981cd6d64f6e76a6c15ee6e856175
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 log

Security for fastsandbox 0.1.0

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.

Select from 5 files

Attestation for fastsandbox-0.1.0.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page