Sandfort / Article
Run the code your agent writes on your own hosts
Sandfort is a self-hosted sandbox server for AI-generated code. This is the shortest path from a checkout to a command running in an isolated container. It needs Python 3.12 and a local Docker daemon. Development uses SQLite, so no separate database server is involved.
Published: 2026-11-24Sandfort 0.1.0
Start the server from the repository root.
.venv/bin/python -m sandfort.admin_cli migrate .venv/bin/python -m sandfort.admin_cli bootstrap --org-name Acme --org-slug acme .venv/bin/uvicorn --factory sandfort.main:create_app
bootstrap creates an organization and prints an API key that starts with sf_. The key is printed once, and stderr says "Store this key now. It cannot be shown again." Copy it before you close the terminal.
Now create a sandbox with the Python SDK (sandfort-sdk) and run a command in it.
from sandfort_sdk import Client
client = Client(base_url="http://127.0.0.1:8000", api_key="sf_...")
sbx = client.create_sandbox(name="hello", snapshot="python:3.12-slim", wait=True)
r = sbx.process_exec(argv=["python3", "-c", "print(21 * 2)"])
print(r.exit_code, r.stdout.strip()) # 0 42
client.stop(sbx.id)
client.delete(sbx.id)The command ran inside a Docker container, and the exit code and stdout came back through the API. For an agent, the exit code is the cheapest feedback signal there is. It decides whether to continue, and stdout says what happened. The rest of this article covers what sits behind those calls and where the edges are.
The problem
An agent that writes code has to run it somewhere. A single python3 -c is the easy case. A coding agent also needs a working directory it can write files into, a git checkout it can commit from, and commands that run longer than one request, such as test suites and dev servers. The code comes from a model, so it cannot run in the agent's own process or on the host without a boundary.
Hosted sandbox APIs solve this, but the code, the repositories and the outputs then leave your infrastructure. Some teams cannot accept that. Others want the same kind of API on hosts they control.
Why raw Docker is not enough on its own
docker run gives you a container. It does not give you the rest of the work that a shared agent backend needs.
- Lifecycle. Create, start, stop, resize (stopped sandboxes only) and delete run as async jobs. Auto-stop and auto-delete timers clean up sandboxes an agent forgot. After a server crash, a reconciler adopts or removes the containers it finds, so a restart does not leave orphans.
- Access. The API key is shown once at creation. People get roles
admin,developerorviewer, and OIDC SSO is available for sign-in. - Accountability. Every organization gets a hash-chained, tamper-evident audit log. Tamper-evident is a narrower claim than tamper-proof.
audit-verifyexits with code 3 when a chain is broken, so it can run in CI or cron. - Limits per tenant. Per-org quotas are reserved transactionally, so one agent in a loop does not consume the host. Metering produces a usage report. Webhooks are signed.
None of this is hard to describe. It is a lot to build and maintain next to the agent you set out to write.
What the server exposes
The REST API has 91 HTTP operations. Around it sit the Python SDK, a CLI, a TypeScript SDK that covers a subset of the Python one, and an MCP server. The only driver is Docker.
Timing from examples/benchmark.py on one host, macOS arm64 with Docker 29.8.2 and alpine:3.20 pre-pulled, on 2026-11-01. Creating a sandbox and waiting for it to be started took p50 107 ms and p95 145 ms over 20 creates. A short command took p50 18 ms and p95 25 ms over 50 commands. This is one local measurement on one host. It is not an SLO and not a comparison with any other product. Run the script on your own host before you plan around it.
The agent tool loop
docs/recipes/agent-tool-loop.md wires a Claude tool-use loop, built on the Anthropic Python SDK, to a sandbox. The model gets three tools.
run_commandruns a command in the sandbox.write_filewrites a file into the sandbox.read_filereads a file back.
The loop is the usual one. Send the task and the tool definitions to the model. When the response contains tool calls, run each one against the sandbox and send the results back as tool results. Repeat until the model answers without a tool call. Every command runs in the sandbox, not in the process that hosts the agent.
You can run the loop without an API key. examples/agent_tool_loop.py drives the same three tools with a scripted stand-in model and exits non-zero on any failure, so it also works as a smoke test of your install.
Isolation tiers and what they do not give you
Every sandbox starts with cap_drop set to ALL plus a minimal add-back list, no-new-privileges, a seccomp profile, pids_limit, and CPU, memory and disk limits. The metadata IP is blocked. network.block_all is optional per sandbox.
A per-sandbox egress_allowlist lets named hostnames through a CONNECT proxy. Read that control carefully. It matches hostnames, it is set at create time, and it is not a firewall. On the container tier, DNS is a side channel.
You choose an isolation tier per sandbox.
| Tier | What it is | Limit |
|---|---|---|
container |
A hardened container | Shares the host kernel |
gvisor |
A user-space kernel | Not a hardware boundary. Measured 3x to 9x overhead on spawn-heavy and small-file work |
microvm |
Kata Containers | Needs KVM |
The container and gvisor tiers need no KVM, so they run on an ordinary Docker host. A Firecracker driver exists in the tree as a skeleton. It is not offered, and you should not plan around it.
Limits
Read these before you adopt it.
- The version is
0.1.0. There are no production references. - Each sandbox is placed on one node.
- The nodes that run sandboxes expose the Docker socket to the server, which gives control over the whole node. Dedicated nodes are recommended.
- There is no built-in TLS. Terminate TLS in a proxy in front of the API.
- The fs API has no chmod, search or replace. The git API has no branch or checkout. Use
process_execfor those. - The TypeScript SDK is a subset of the Python SDK.
- Resize works only on stopped sandboxes.
Where to go next
The server is source-available under FSL-1.1-Apache-2.0. The SDKs and CLI are Apache-2.0.
Start with the three server commands and the # 0 42 snippet above. Then run examples/agent_tool_loop.py, and read docs/recipes/agent-tool-loop.md before you connect a real model.