Metadata-Version: 2.4
Name: fastsandbox
Version: 0.3.0
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Rust
Classifier: Typing :: Typed
Requires-Dist: pydantic>=2.14,<3
License-File: LICENSE-APACHE
License-File: LICENSE-MIT
Summary: Run code and coding agents in throw-away Docker Sandboxes, from Python.
Keywords: agents,ai,docker,sandbox,sbx
Author-email: Aurelien Andre <aurelien.andre@aartintelligent.fr>
License-Expression: MIT OR Apache-2.0
Requires-Python: >=3.12
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://aartintelligent.github.io/fastsandbox/
Project-URL: Repository, https://github.com/aartintelligent/fastsandbox

# fastsandbox

**Run code and coding agents in isolated sandboxes, from Python.**

fastsandbox lets a Python program hand work to
[Docker Sandboxes](https://docs.docker.com/ai/sandboxes/): a test suite to run
on a copy of a repository, an issue for a coding agent to fix, a tool to try
out. It gets back a typed result, and the sandbox is gone.

[![CI](https://github.com/aartintelligent/fastsandbox/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/aartintelligent/fastsandbox/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/aartintelligent/fastsandbox/graph/badge.svg)](https://codecov.io/gh/aartintelligent/fastsandbox)
[![PyPI](https://img.shields.io/pypi/v/fastsandbox.svg)](https://pypi.org/project/fastsandbox/)
[![Python](https://img.shields.io/python/required-version-toml?tomlFilePath=https://raw.githubusercontent.com/aartintelligent/fastsandbox/main/pyproject.toml)](https://aartintelligent.github.io/fastsandbox/get-started/installation/)
[![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](https://aartintelligent.github.io/fastsandbox/project/license/)
[![Monthly Downloads](https://static.pepy.tech/badge/fastsandbox/month)](https://pepy.tech/projects/fastsandbox)

[![Requires Docker Sandboxes](https://img.shields.io/badge/requires-Docker%20Sandboxes-2496ED?logo=docker&logoColor=white)](https://aartintelligent.github.io/fastsandbox/get-started/installation/)

[![Claude Code plugin](https://img.shields.io/badge/Claude%20Code-plugin-D97757?logo=claude&logoColor=white)](https://aartintelligent.github.io/fastsandbox/get-started/claude-code/)

[Documentation](https://aartintelligent.github.io/fastsandbox/) ·
[Quickstart](https://aartintelligent.github.io/fastsandbox/get-started/first-steps/) ·
[API reference](https://aartintelligent.github.io/fastsandbox/reference/) ·
[Examples](https://aartintelligent.github.io/fastsandbox/guides/examples/) ·
[docker-sandbox, the Rust crate underneath](https://github.com/aartintelligent/docker-sandbox)

fastsandbox is an independent, community-maintained project. It is not
affiliated with, sponsored or endorsed by Docker, Inc., and uses the Docker
name only to say which product it is made for.

## Docker Sandboxes, in a few words

[Docker Sandboxes](https://docs.docker.com/ai/sandboxes/) runs code, and coding
agents, in throw-away microVMs on your machine. Each sandbox has its own
system, its own files and its own network rules. Its proxy applies the
network policy and can add the credentials of a service to the requests sent
to it, so that most secrets need not be inside the sandbox. A sandbox is
created from a kit, which says what it holds: a plain shell, or a coding agent
such as Claude Code or Codex, ready to work. All of it is driven by the `sbx`
CLI, which talks to a daemon, `sandboxd`, through a socket.

For anyone who runs coding agents, this changes what they can be trusted with.
An agent can edit files and run commands without asking, inside a machine
thrown away after the run. It can work on a clone of your repository rather
than the repository itself, with network rules for its sandbox. What it can
still reach, a mounted directory, a host the policy allows, a key the proxy
writes for it, is what you give it: see the
[security model](https://aartintelligent.github.io/fastsandbox/guides/security/).

## The goal of this stack

Without a library, a Python program that wants a sandbox runs the CLI and
parses what it prints. fastsandbox talks to the socket of the daemon instead.

It is built on [`docker-sandbox`](https://github.com/aartintelligent/docker-sandbox),
Rust crates by the same author that do all the work with the daemon:
`docker-sandbox` is the client of the socket, which maps the API of the daemon
version by version and checks the version of the daemon when it connects;
`docker-sandbox-kit` makes the kits sandboxes are created from;
`docker-sandbox-blueprint` describes a whole sandbox as data and launches it.
fastsandbox brings them to Python through a native extension, and adds two
layers: a typed async client that reaches every route of the daemon, and
**FastSandbox**, where the work done in a sandbox is a typed function under a
decorator.

What that buys you, in practice:

- **Work declared, not scripted.** `@app.task` and `@app.agent` put the kit,
  the network rules, the deadline and the credentials of a sandbox next to the
  function that uses it. The signature of the function validates its inputs
  and its result.
- **Every agent `sbx` knows, one way.** Claude Code, Codex, Copilot, Cursor,
  Devin, Docker Agent, Droid, Kiro and OpenCode are all run the same way: one
  prompt run unattended, a stream of what the agent reports as it goes, or an
  interactive session.
- **Keys held by the proxy.** The API key of an agent is read from your
  environment and given to the proxy of the sandbox of the run only, which
  writes it into the requests the agent sends to its service; the agent only
  sees a placeholder. Kiro is the exception: its key is a variable of the
  sandbox.
- **Tools for the agent.** MCP servers, served by the host, remote, or started
  in the sandbox, are registered in Claude Code, Copilot or OpenCode by the
  task itself, with a token drawn for each run.
- **Your repository untouched.** On a private clone, the agent may change and
  commit anything. Its work comes back as a patch to review, and your
  directory stays as it was.
- **Sandboxes that clean up after themselves.** The sandbox of a run is
  deleted when the run ends, also on an error, a timeout or Ctrl-C, unless
  the task keeps it. A killed process, a second Ctrl-C during the cleanup or
  a failed deletion leaves it behind, and `sbx ls` shows it.
- **Errors you can act on.** A missing sandbox, a deadline or a failed command
  each raise their own error class, with typed details, not a message to
  parse.
- **Tests without a daemon.** A fake daemon serves the socket API in memory,
  so the code that drives sandboxes is tested in any CI.

## Where it fits

- **Coding agents on your repositories**: a fix, a review, a patch from a
  private clone, or several agents on one issue with the tests choosing the
  patch that holds.
- **Checks in a throw-away machine**: a test suite, a build or a linter on a
  copy of a repository, with network rules of its own on top of the global
  policy of the daemon.
- **Code you would rather not run on your machine**: run it in a sandbox
  instead, then read its output and, before the sandbox goes, the activity
  log of the hosts it reached.
- **Agents with tools**: the MCP servers an agent needs, registered in the
  agent of its sandbox, or loaded into the MCP gateway of the sandbox.
- **Sandboxes described as data**: a sandbox spec holds the kit, the mounts,
  the network rules, the keys and the MCP servers of a sandbox, as JSON if
  need be, and launches as many sandboxes alike as a job needs.
- **Tooling around the daemon**: a watcher on its events, an audit of the
  network policy, a cleanup of old sandboxes and images.

## Getting started

Install [Docker Sandboxes](https://docs.docker.com/ai/sandboxes/) first, its
daemon running for your user: fastsandbox connects to its socket and does
nothing without it. Then, with Python 3.12 or newer:

```sh
uv tool install fastsandbox   # the command; in a project: uv add fastsandbox
fastsandbox info              # finds the daemon and checks its API version
```

The [quickstart](https://aartintelligent.github.io/fastsandbox/get-started/first-steps/)
runs a first sandbox with no AI account. An agent task: Claude Code explains a
project, working on a private clone of it.

```python
from pathlib import Path
from typing import Annotated

from fastsandbox import Context, FastSandbox, WorkspaceDir
from fastsandbox.exceptions import TaskError

app = FastSandbox("quickstart")


@app.agent("claude", timeout="15m")
async def explain(ctx: Context, repo: Annotated[Path, WorkspaceDir(clone=True)]) -> str:
    """Has Claude Code explain a project, working on a private clone of it."""
    workdir = str(repo.resolve())
    run = await ctx.agent.prompt(
        "Explain what this project does and how its code is laid out, "
        "in twenty lines at most, and write the explanation to EXPLAINED.md.",
        working_dir=workdir,
    )
    if not run.ok:
        raise TaskError(f"Claude Code exited with {run.exit_code}: {run.stderr.strip()}")
    # The file is in the clone, inside the sandbox: the host is untouched.
    return await ctx.sandbox.read_text(f"{workdir}/EXPLAINED.md")
```

```sh
export ANTHROPIC_API_KEY=sk-ant-...   # not needed with a Claude subscription
fastsandbox run agent.py explain --repo .
```

**With a Claude subscription, no API key is needed.** Leave
`ANTHROPIC_API_KEY` unset: Claude Code then uses the subscription Docker
Sandboxes holds, once you have signed in with it under `sbx` (`sbx run claude`,
then `/login`). Like a key, it stays with the proxy: the sandbox never holds it.

Each run calls the API of the agent's provider, billed to your key or
counted against your subscription.
[Your first coding agent](https://aartintelligent.github.io/fastsandbox/get-started/quickstart/)
explains this task line by line. From there, the
[documentation](https://aartintelligent.github.io/fastsandbox/) covers what a
real setup needs: an agent's repository, its network, following its work,
giving it tools, then tasks, the client and testing.

### With Claude Code

The repository is also a marketplace of Claude Code plugins. Its plugin teaches
Claude the whole library and adds commands that set up a project, check the
machine and add tasks:

```text
/plugin install fastsandbox --marketplace aartintelligent/fastsandbox
```

See [With Claude Code](https://aartintelligent.github.io/fastsandbox/get-started/claude-code/).

## Status

fastsandbox is in alpha. It covers:

- the whole socket API of the daemon;
- kits forged without the `sbx` CLI, or compiled by it, and kept for the next
  sandboxes;
- sandbox specs, launched in one call;
- tasks and agent tasks, with the nine agents of `sbx` and their MCP servers;
- the MCP gateway;
- the fake daemon for tests.

It runs on Linux and macOS, where Docker Sandboxes runs.

The socket API of Docker Sandboxes is private and changes with `sbx` releases.
Each release of fastsandbox is checked against a range of API versions, and
connecting to a daemon outside that range fails unless you allow it. The API
of fastsandbox itself may still change before 1.0. Such changes are listed in
the [changelog](https://github.com/aartintelligent/fastsandbox/blob/main/CHANGELOG.md).

## FAQ

**Is this an official Docker project?** No. fastsandbox is independent and
community-maintained. Docker Sandboxes, its licence and its roadmap belong to
Docker, Inc.

**Do I need Docker Sandboxes installed?** Yes. fastsandbox is a client of its
daemon and connects to the `sandboxd` socket, and that is all it uses: it forges
the kits it needs through the socket, without the `sbx` CLI. The CLI is used
only for a kit that it alone resolves, such as a local kit directory, when
asked.

**Can it drive the Docker Engine, containers and images?** No. It works only
with Docker Sandboxes; containers and images outside it are the job of the
Docker SDK.

**Does my API key enter the sandbox?** No, for every agent but Kiro. The
sandbox holds a placeholder, and its proxy writes the key in its place in the
requests the agent sends to its service. Kiro has no service in `sbx`, so its
key is given to the sandbox as an environment variable, and is visible inside
it.

**Is it safe to let an agent run unattended?** The isolation is that of Docker
Sandboxes; fastsandbox decides what crosses it: which directory, which hosts,
which credentials. The global network policy of `sbx` may allow every host,
and the rules of a sandbox add to it rather than replace it: check it, and
deny what an unattended agent must not reach. Then check its work with the
tests of the project rather than trusting what it reports. The
[security model](https://aartintelligent.github.io/fastsandbox/guides/security/)
goes through each point.

**Can I test my code without a daemon?** Yes. `fastsandbox.testing` serves the
socket API from memory: no `sbx`, no image, no microVM.

**Is it production ready?** Not yet: it is in alpha, before 1.0. Every
change runs the following checks:

- the tests on Linux, and on macOS when the package changes;
- mypy in strict mode;
- a coverage threshold;
- the build of the documentation;
- an audit of the Rust and Python dependencies.

The socket API it relies on is private, though: read the status above before
building a product on it.

**How is it organised?** A Python package over the crates of
[`docker-sandbox`](https://github.com/aartintelligent/docker-sandbox), joined by
a thin native extension, and laid out as they are: `fastsandbox.client` binds
the client of the socket, `fastsandbox.kits` the kits, `fastsandbox.blueprint`
the sandbox specs, and `fastsandbox.framework`, FastSandbox, is Python alone;
every public name is imported from `fastsandbox` itself. Everything about the
daemon is in the crates: a new route or field of the daemon goes into them
first, then into fastsandbox. Every helper and every default is Python. The
[design page](https://aartintelligent.github.io/fastsandbox/overview/design/)
records the layers and the decisions behind them.

## Contributing

See [CONTRIBUTING.md](https://github.com/aartintelligent/fastsandbox/blob/main/CONTRIBUTING.md):
setting up, the checks, commits and pull requests. To report a vulnerability,
see the [security policy](https://github.com/aartintelligent/fastsandbox/blob/main/SECURITY.md).

## License

Licensed under either of [Apache License, Version 2.0](https://github.com/aartintelligent/fastsandbox/blob/main/LICENSE-APACHE)
or [MIT license](https://github.com/aartintelligent/fastsandbox/blob/main/LICENSE-MIT)
at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this work by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.

