Sandboxing
Contain what an agent's code and commands can reach: filesystem and network isolation together, the isolation primitives, and what a sandbox does not protect.
Why a sandbox
Permissions decide whether a command may be attempted. A sandbox limits what any command can touch once it runs, even if it was approved by mistake or the model was manipulated. Claude Code’s docs describe the split directly: modes decide whether to ask, and the sandbox and outer isolation boundaries decide what an action can reach4.
Anthropic notes that a coding agent running on a user’s machine has access to their filesystem, shell and network, and that without this access such agents are of limited use, so the access has to be granted safely2.
Two boundaries, both needed
Anthropic’s engineering post names two boundaries. Filesystem isolation means the agent can only access or modify specific directories, which stops a prompt-injected agent from altering sensitive system files. Network isolation means it can only connect to approved servers1. The post stresses that effective sandboxing needs both1. Without network isolation, a compromised agent could send out files such as SSH keys, and without filesystem isolation, it could escape the sandbox and reach the network1.
Diagram: my own.
Isolation primitives
Different surfaces use different mechanisms. A third-party summary of Anthropic’s containment post describes three patterns: ephemeral gVisor containers for the web product, OS-level sandboxes combined with human approval for the local command-line tool, and full virtual-machine isolation for a desktop agent product3. I have not independently checked those details; read the primary post for them.
In general, the options trade strength against cost (my own summary):
| Primitive | Strength | Cost |
|---|---|---|
| OS-level process sandbox (namespaces, seccomp, similar) | Light, fast start | Shares the host kernel |
| Container with a user-space kernel such as gVisor | Stronger syscall barrier | More overhead |
| Virtual machine | Separate kernel | Heaviest, slower start |
Pick by threat: code you wrote and trust needs less than arbitrary code an agent generates after reading the open web.
Layer the controls
Anthropic’s Agent SDK deployment guide recommends layering for high-security settings: container isolation, network restrictions, filesystem controls and more5.
Diagram: my own.
What a sandbox does not do
- It does not stop misuse of allowed channels. If a domain is on the allow list, injected instructions can still send data to it, or to any service that domain lets users write to. Keep allow lists short and specific (my own caution).
- It does not protect secrets placed inside it. Anything in the environment is reachable. Keep credentials out, or scope them tightly.
- It does not cover tools outside it. MCP servers and APIs the agent calls run elsewhere; scope them separately (Permissions).
- It does not guarantee correctness. A contained agent can still delete the project folder it is allowed to edit. Use version control and backups.
Practical setup
- Mount only the project directory, read-only where possible.
- Default-deny network, then add the registries and APIs the task needs.
- Run as a non-root user with CPU, memory and time limits.
- Make the sandbox ephemeral for untrusted work, so state does not persist.
- Fail closed: if the sandbox cannot start, do not run the command unsandboxed.
- Log commands and network attempts (Tracing and monitoring).
For the coding use case, see Coding agents.
Sources
- [1]Beyond permission prompts, making Claude Code more secure and autonomous — Anthropic Engineering · 2025PARAPHRASED
- [2]How we contain Claude across products — Anthropic Engineering · 2026OPENING PASSAGE ONLY; DETAILS VIA THIRD-PARTY SUMMARIES
- [3]How Anthropic Contains Claude: 3 Isolation Patterns for Shipping Safe AI Agents — Tyson Cung, DEV Community · 2026THIRD-PARTY SUMMARY OF THE ANTHROPIC POST
- [4]Permission modes — Anthropic, Claude Code docsPARAPHRASED
- [5]Securely deploying AI agents — Anthropic, Agent SDK docsPARAPHRASED