Part 9 of 13 · 4 min read
Production sandboxes and lifecycle
How a production sandbox compares, and design choices.
How a production sandbox compares
Everything above ran on one machine, as processes sharing one kernel. Anthropic's guide to securely deploying agents (read 24 October 2026) compares four levels of isolation:
| Technology | Isolation | Overhead | What it adds |
|---|---|---|---|
Sandbox runtime (bubblewrap on Linux, sandbox-exec on macOS) |
good, secure defaults | very low | filesystem and network rules at the operating-system level, a built-in proxy |
| Containers | depends on setup | low | namespaces, capability dropping, system-call filter, read-only root, memory and process limits, --network none |
| gVisor | excellent when set up right | medium to high | a user-space kernel that handles system calls, so the host kernel is not directly exposed |
| Virtual machines (Firecracker, QEMU) | excellent when set up right | high | a separate kernel and hardware isolation |
That guide's figures for gVisor are about 0 percent for pure computation, roughly twice as slow for simple system calls, and up to 10 to 200 times slower for file-heavy work. Two things in it match this module. The network is handled by a proxy that lives outside the wall, reached over a Unix socket. The program cannot connect anywhere itself. The proxy applies an allowlist, keeps a log, and can inject credentials so the agent never sees them. And a sandbox that shares the host kernel can in principle be escaped by a kernel bug. That is the case for gVisor or a virtual machine when the code is truly hostile or from many tenants. The example is in the first group.
Claude Code's own sandbox, as documented, uses the same operating-system primitives (Seatbelt on macOS, bubblewrap on Linux). Reads and writes are allowed in the working directory. The network goes through a proxy with domain approval. Its limits are stated. The proxy filters by the host name the program asks for and does not inspect encrypted traffic. So a broad allowed domain can be an exfiltration path. And an allowed Unix socket such as the Docker socket can hand over the host.
State and lifecycle: design choices
| Question | This example | The other way |
|---|---|---|
| Do variables survive between calls? | No: each run is a new process. Files survive. | A persistent interpreter (a notebook kernel) keeps variables, so it is more natural for data work, but it is harder to limit, harder to reset, and a bug or an attack in one call lives on into the next |
| One sandbox per what? | per conversation (a session with a quota and a run count) | per call (cleaner, slower, no files between calls), or per user (cheaper, weaker isolation between conversations) |
| Who deletes it? | the session's own end; the experiment tests it | a time-to-live and a janitor, because "the session ended" is not guaranteed |
| What happens when the disk quota is full? | the next run is refused with a message; deleting files restores it | a hard cap by the filesystem itself, which does not rely on the check |
These are the choices; the specification of any tool you use may differ.
What the example does not do
About this example What the example does not do
- No system-call filter. Production sandboxes restrict which kernel calls a program can make. This one does not, and the program holds a "root inside a user namespace" identity.
- No control groups. Memory limits are on address space, which is not the same as real memory used; process counting is by polling.
- No network allowlist. The network is all on or all off. A real agent usually needs a few named destinations through a proxy.
- One operating system. It needs Linux with unprivileged user namespaces. It refuses to run elsewhere.
- A scripted agent. No real model was used. The conclusions about what a model would do from a reply are assumptions.
- Python only, standard library only. Installing packages is its own problem (where from, whether to allow a network at install time, whether to cache): not covered.
- The sixteen programs are the example's own. They are bounded, and written by someone who knows the sandbox. A real attacker has more imagination. A passing table is evidence that the layers do what they claim, not that nothing gets through.
How to build it so it holds up
- Enforce every limit yourself if the kernel does not for the privilege level you run at — because
RLIMIT_NPROCis silently ignored for root, and a sandbox that trusts it is unprotected without knowing it. - Set the hard limit above the soft one, with margin for namespace quirks — because a process-id namespace's first process ignores the soft limit's signal entirely.
- Isolate both filesystem and network, never just one — because each protects what the other cannot: the network layer stops a secret leaving, the filesystem layer stops it being read at all.
- Resolve a file name through every symbolic link before deciding it is inside the sandbox — because checking for
..and an absolute path catches nothing a link can't route around. - Fail closed when isolation cannot be set up — because a sandbox that quietly runs unsandboxed is worse than no sandbox, since everyone still believes it is there.
- Give the tool wording for every distinct stop reason, not just an exit code — because a model cannot act on a cause it was never told.
- Plant defects in your own 26 checks before trusting them — because a passing suite proves nothing about a bug it was never shown.