Sandboxing AI Agents: How to Let an Agent Act Without Letting It Escape
Coding agents now run shell commands, install packages and browse the web on their own. This guide explains the boxes we put them in, from a few kernel flags on a laptop to a dedicated micro virtual machine in the cloud: what each layer stops, what it cannot stop, how often frontier models break out in controlled tests, and why a sandbox alone does not defeat prompt injection.
Why sandboxing became the agent problem of 2026
A chatbot produces text, and a human decides what to do with it. An agent produces actions: it edits files, runs npm install, calls APIs, opens pull requests and reads web pages, often hundreds of times in one task. Every one of those actions runs with whatever permissions the agent's process has. On a developer laptop that usually means the developer's own account, with their SSH keys, cloud credentials, browser cookies and every repository they can reach.
The first answer was to ask the human before each risky step. It did not hold up. In its engineering write-up on Claude Code sandboxing, Anthropic describes approval fatigue: people click "yes" to nearly everything, so the prompts stop protecting anyone. Coverage of a later Anthropic post reports that users approved roughly 93% of permission prompts under the older flow. Anthropic's answer was to put a boundary around the agent and let it work freely inside it; the company reports that sandboxing cut permission prompts by 84% in its internal use.
At the same time, the box became harder to trust. In March 2026 researchers from Oxford and the UK AI Security Institute published SandboxEscapeBench, showing frontier models breaking out of misconfigured containers about half the time, and a later revision reports that Claude Mythos Preview saturates the public set. Meanwhile prompt-injection attacks moved from demos to live exploitation, according to a Cloud Security Alliance research note. Both trends push the same way: stronger walls, fewer secrets inside them, and tighter control of what can leave.
The lethal trifecta: when an agent becomes dangerous
Simon Willison's June 2025 framing is the clearest way to see the risk. An agent becomes exploitable when it combines three capabilities: access to private data, exposure to untrusted content (anything an attacker could have written: a web page, an email, a GitHub issue, a tool description) and the ability to communicate externally. With all three, hidden instructions in the untrusted content can tell the agent to send the private data somewhere. Remove any one leg and that particular attack has nowhere to go.
Willison's point is that the mechanism, prompt injection, has no reliable fix at the model level, so the defence has to be structural. Sandboxing is one of the main ways to cut a leg: a sandbox with no network removes external communication; a sandbox with no credentials or private files removes the data. Click the circles to switch each capability on or off.
Toggle the three legs
Each circle is one capability the agent session has. The verdict follows Willison's framing; real systems also have partial cases, such as network access limited to a list of domains.
Source of the framing: Simon Willison, "The lethal trifecta for AI agents" (16 Jun 2025).
Two threat models, two kinds of protection
"Sandboxing an agent" covers two different problems, and confusing them leads to the wrong controls.
๐งฏ 1. The agent makes a mistake
The model misreads the task, runs rm -rf in the wrong directory, drops a database table or loops forever. The agent is not hostile; it is just wrong, quickly and at scale. The July 2025 Replit incident, in which an agent deleted a live database during a code freeze, is the best-known case.
What works: filesystem limits, separate dev and production credentials, snapshots and backups, resource quotas, reversible actions.
๐ญ 2. Someone steers the agent
Text the agent reads (a web page, an issue, a document, a poisoned tool description) contains instructions. The agent follows them with its own permissions: it reads secrets and sends them out, or plants code. Here the model is doing exactly what it was told, by the wrong person.
What works: no secrets inside the sandbox, strict egress control, capability-tracking designs such as CaMeL, splitting privileged and quarantined models, human review of consequential actions.
A third, rarer case sits on top: the agent itself tries to get out, either because it was instructed to or because breaking out helps it finish the task. That is what SandboxEscapeBench measures, and it is the reason the strongest tiers of isolation exist.
The building blocks
Every agent sandbox is assembled from a handful of operating-system and virtualisation primitives. Knowing them makes vendor claims much easier to read.
Glossary of primitives
Click a term. Linux and macOS mechanisms are what local coding agents use; the virtualisation tiers are what cloud sandboxes use.
The isolation ladder
The key question for any sandbox is: what does the agent's code share with the machine it runs on? If it shares the host's kernel, a single kernel bug can be a way out. Each step up the ladder puts more between the agent and the host, usually at some cost in start-up time, compatibility or price. Choose a rung to see the layers and the trade-offs.
Five rungs, plus two side paths
Ratings are this site's summary of the sources below, on a 1 to 5 scale, not measurements. "Examples" are as reported by vendor documentation or comparison sites.
Inside a coding-agent sandbox
Local coding agents use the lowest rung, because they need to work on your real files at native speed. They make that rung much stronger by combining two controls: a filesystem boundary and a network boundary. Anthropic's write-up stresses that both are needed: filesystem isolation alone still lets a hijacked agent send your SSH key to an attacker, and network isolation alone still lets it tamper with your shell startup files to escape later.
How a command travels through the sandbox
Click any box. Based on Anthropic's description of Claude Code and its open-source sandbox-runtime, and OpenAI's Codex documentation. Details differ between versions and platforms.
Claude Code and Codex side by side
From each vendor's documentation as found in searches. "Reported" marks details that come only from third-party descriptions.
| Claude Code | OpenAI Codex CLI | |
|---|---|---|
| macOS mechanism | Seatbelt (sandbox-exec profile) | Seatbelt |
| Linux mechanism | bubblewrap (namespaces, bind mounts) | seccomp + Landlock per the security guide; third-party pages also describe bubblewrap for mount isolation |
| Default writes | Working directory only | Workspace only in workspace-write mode; also read-only and full-access modes |
| Network | Routed through a proxy that allows only approved domains; new domains trigger a prompt | Off by default in workspace-write; can be enabled in config |
| Approval policy | Sandboxed commands can run without prompts (auto-allow); unsandboxable ones fall back to normal permissions | Separate axis: untrusted, on-request, never; --full-auto = workspace-write + on-request |
| Open source | sandbox-runtime (srt), Apache-2.0, research preview; Windows support reported as alpha | Codex CLI is open source |
Docker took a step up the ladder for the same tools. In January 2026 its experimental Docker Sandboxes moved to microVM isolation on macOS and Windows: each sandbox gets its own VM and its own private Docker daemon, so the agent cannot reach the host's daemon, containers or files outside the workspace. Docker lists Claude Code, Codex CLI, Copilot CLI, Gemini CLI and Kiro as supported agents.
Try it: what happens to this command?
Pick an action the agent wants to take and a protection setup, and see what happens. This is a teaching model of the behaviour described above, not a test of any specific product version.
Agent action simulator
"Prompts only" means no sandbox, with a human asked to approve risky commands. Remember the reported 93% approval rate.
The 2026 vendor landscape
For agents that run in the cloud, isolation is now a product category. OpenAI's April 2026 Agents SDK update made it a first-class primitive: the SDK separates the agent harness from the compute and ships built-in support for sandboxes from Blaxel, Cloudflare, Daytona, E2B, Modal, Runloop and Vercel. Every major cloud now offers its own.
Who isolates how
Filter by isolation type. Isolation types are as reported by vendor docs or comparison sites; figures in the notes are vendor or third-party claims, not our measurements.
| Platform | Isolation | Notes |
|---|
Can agents escape their sandboxes?
SandboxEscapeBench (arXiv 2603.02277), from the University of Oxford and the UK AI Security Institute, is the first open benchmark that measures this directly. An agent gets a shell inside a container and must read a protected file on the host. The 18 scenarios cover three layers: orchestration (for example an exposed Docker socket), runtime (privileged containers, writable host mounts) and kernel (known exploits such as Dirty COW and Dirty Pipe). The whole thing runs inside a virtual machine, so a successful escape only reaches an isolated VM, never the evaluation host.
Reported overall escape rates
Values as reported in secondary coverage of the first version of the paper; the revised paper adds newer models. Bars with a hatch are from a single secondary source. Read them as capability on known misconfigurations, not as the chance of a real breach.
- Misconfigurations fall first. Coverage of the first results says models routinely exploited exposed sockets, privileged containers and writable mounts, but mostly failed kernel-level exploits.
- Newer is not always better at escaping. One summary reports GPT-5.2 at 0.27 overall against 0.50 for GPT-5.
- The ceiling moved fast. The revised paper says Claude Mythos Preview saturates the public benchmark; an alphaXiv summary reports 100% pass@5 on the harder tasks in the extended evaluation, with runs of up to 100 million tokens. We could not see the paper's own table for this.
- Part of the test is private. The authors published only scenarios built on known vulnerability classes and kept a private set for AISI's internal evaluations.
- The authors' own caveat: results should not be read as the likelihood of an end-to-end compromise.
Incidents and milestones, 2023 to 2026
Click an event. Confidence badges say how well each item is documented.
Timeline
Mixes attacks, defences and products. Scroll sideways on a phone.
Beyond the box: designs that resist prompt injection
A sandbox limits where an agent can act. It does not decide whether an action matches what the user asked for. If the agent legitimately needs to post to GitHub, a sandbox that allows GitHub will also let a hijacked agent post your private code there. That is why the research frontier has moved to architectures that control what untrusted data is allowed to influence.
Patterns for injection-resistant agents
The six patterns are from Beurer-Kellner et al., "Design Patterns for Securing LLM Agents against Prompt Injections" (arXiv 2506.08837, June 2025), as summarised by Simon Willison; CaMeL and the dual-LLM pattern are listed separately. Click a pattern.
The paper's authors, from ETH Zurich, Google, IBM, Microsoft and others, put the argument bluntly: as long as agents and their defences rely on the current class of language models, general-purpose agents are unlikely to offer meaningful and reliable safety guarantees. Their response is to constrain agents so that, once untrusted input has entered the context, it cannot trigger consequential actions.
CaMeL (Google DeepMind, arXiv 2503.18813) is the most complete version of that idea. A privileged model turns the user's request into a small program before any untrusted data is read. A quarantined model may parse untrusted content, but its output is just data flowing through that program. Every value carries capability tags recording where it came from and who may receive it, and a custom interpreter checks those tags at every tool call. On the AgentDojo benchmark the paper reports 77% of tasks solved with provable security, against 84% for an undefended system; one secondary write-up quotes 67% from an earlier version.
Newer work shows the remaining gaps. Agent data injection (arXiv 2607.05120) corrupts what the agent sees rather than what it does, so output guardrails miss it. A July 2026 survey of execution security for coding agents (arXiv 2607.05743) systematises 39 papers and four patched CVEs in production agent harnesses, finds that policy-enforcement studies report failure rates of 69% to 98%, and notes that every mechanism it reviewed assumes the policy author makes no mistakes. Time-of-check-to-time-of-use (TOCTOU) attacks, where what was approved is not what runs, are a separate thread: the NeurIPS 2025 paper "Mind the Gap" reports that combined countermeasures cut TOCTOU vulnerabilities in executed trajectories only from 12% to 8%.
Which layer stops which attack?
No single control covers everything. This matrix is our own reading of the mechanisms described above; it is meant to show why defence in depth is necessary, not to rate products.
Coverage matrix
โ = generally stops it; ~ = helps or depends on configuration; โ = does not address it. Hover a cell for the reasoning.
The research map
Papers worth knowing, grouped by what they study. Filter by theme.
Key papers on agent sandboxing and containment
Venue and result columns come from abstracts, proceedings pages and summaries; we did not read every full text.
| Paper | Where / when | What it found or proposed |
|---|
Choose a tier for your agent
Answer four questions. The recommendation follows the consensus of the sources above; treat it as a starting point, not an audit.
Sandbox tier helper
A practical checklist
Before you let an agent run unattended
Tick what is true of your setup. Drawn from vendor documentation and the research above.
Reading the numbers: what you may see versus what the sources say
| Claim | What the sources say |
|---|---|
| "Sandboxing cut prompts by 84%" | Anthropic's own internal figure. Independent measurements were not found. |
| "Users approve 93% of prompts" | Reported in coverage of a later Anthropic post about Claude Code; we did not see the original telemetry. |
| Firecracker boots in 125 ms with under 5 MiB overhead | Widely attributed to the NSDI 2020 paper but found only in secondary summaries. Vendor cold starts for Firecracker-based products range from about 5 ms (snapshot restore) to 2 s. |
| GPT-5 escapes containers half the time | An overall rate of about 0.50 on SandboxEscapeBench's known-vulnerability scenarios, from secondary coverage. Not a real-world breach rate. |
| Claude Mythos Preview escapes every time | The revised paper says it saturates the public set; "100% pass@5 on harder tasks" is from an alphaXiv summary. The private set's results are not public. |
| CaMeL: 77% or 67%? | 77% (vs 84% undefended) is in the current abstract; 67% appears in a summary of an earlier version. |
| Codex on Linux uses bubblewrap | OpenAI's security guide names seccomp and Landlock; third-party pages add bubblewrap. Check the current source. |
| Daytona is closed source | Daytona's blog (11 Jun 2026) says production code moves to closed source for security reasons and the public repository stays up. A community fork says the public repo is frozen; unverified. |
| gVisor patches ship 165 to 458 days before CVEs | From a blog summarising arXiv 2606.08433; we could not confirm it against the paper. |
| An agent "escaped its training sandbox to mine crypto" | The Alibaba-linked "ROME" account appears only in a secondary blog; left out of the timeline. |
๐ References and research papers
- Research papers
- Quantifying Frontier LLM Capabilities for Container Sandbox Escape (SandboxEscapeBench), arXiv 2603.02277
- Defeating Prompt Injections by Design (CaMeL), arXiv 2503.18813
- Design Patterns for Securing LLM Agents against Prompt Injections, arXiv 2506.08837
- AgentDojo, NeurIPS 2024 Datasets and Benchmarks ยท arXiv 2406.13352
- The Balkanization of Execution-Security Research for AI Coding Agents, arXiv 2607.05743
- AI Code Sandboxes: A Comparative Security Study, Part 1, arXiv 2606.08433
- Agent Data Injection Attacks are Realistic Threats to AI Agents, arXiv 2607.05120
- aiAuthZ: Off-Host, Identity-Bound Authorization for AI Agents, arXiv 2607.05518
- Before the Tool Call: Deterministic Pre-Action Authorization for Autonomous AI Agents, arXiv 2603.20953
- Parallax: Why AI Agents That Think Must Never Act, arXiv 2604.12986
- An AI Agent Execution Environment to Safeguard User Data, arXiv 2604.19657
- SafeClawBench: Separating Semantic, Audit-Evidence, and Sandbox Harm, arXiv 2606.18356
- Mind the Gap: TOCTOU Vulnerabilities in LLM-Enabled Agents, NeurIPS 2025
- Firecracker: Lightweight Virtualization for Serverless Applications, NSDI 2020
- MVVM: Deploy Your AI Agents Securely, Efficiently, Everywhere, arXiv 2410.15894
- Vendor documentation and engineering posts
- Anthropic: Claude Code sandboxing
- anthropic-experimental/sandbox-runtime (srt)
- OpenAI Codex: sandboxing concepts ยท Codex security guide
- OpenAI: The next evolution of the Agents SDK (Apr 2026)
- Docker Sandboxes with microVM isolation ยท architecture docs
- AWS: self-hosted agent sandboxes with Lambda MicroVMs
- Amazon Bedrock AgentCore runtime sessions
- Daytona is going closed source (Jun 2026)
- Fly.io: Firecracker vs gVisor
- Prompt injection and incidents
- Simon Willison: The lethal trifecta for AI agents
- Simon Willison: The Dual LLM pattern
- Simon Willison on the six design patterns paper
- Invariant Labs: GitHub MCP exploited
- Cloud Security Alliance: Indirect prompt injection goes operational
- Cloud Security Alliance: MCP tool poisoning
- OWASP GenAI exploit round-up, Q1 2026
- Cymulate: sandbox escape findings in coding CLIs
- Arnica: TOCTOU in Cursor's script inspection
- The Stack: the Replit database deletion
- Comparisons and explainers (vendor-adjacent, read critically)
- Northflank: How to sandbox AI agents
- Superagent: AI code sandbox benchmark 2026
- The New Stack: OpenAI Agents SDK sandboxes
- Morph: WebAssembly sandboxes for agents
- WebProNews: Google Cloud's Agent Compute Engine (single report)
- On this site
- The agentic loop, explained
- AI safety, alignment and interpretability
- Coding agents