Claude Code wiped a user's entire Mac home directory via a trailing ~/ in an rm -rf command.
The model generated code that deleted the user's home-directory contents entirely.
No malicious intent. Just a statistical output that happened to be catastrophic.
That's the core problem with AI agent sandboxing: the model that generates code cannot distinguish between helpful automation and a command that deletes your filesystem. LLM-generated code emerges from statistical patterns in training data without inherent understanding of security boundaries - it might inadvertently create scripts that attempt to access sensitive files, make network connections, or consume excessive system resources. The model doesn't know what it doesn't know. It just generates the next plausible token.
So the question is not whether to sandbox AI-generated code. The question is how.
What a sandbox actually does
An AI agent sandbox is a securely isolated execution environment that deliberately limits what an AI agent can actually do to the infrastructure that matters. Think of it as giving the agent a full, realistic machine to work in - a Python interpreter, a bash terminal, a filesystem - but with the walls of that machine preventing anything from escaping into your real infrastructure.
AI agents can write files, install packages, run tests, and execute arbitrary code inside the sandbox without any access to the host system, other sandboxes, or production infrastructure. If the agent makes a mistake or gets hijacked, only the sandbox is destroyed. The only thing destroyed is a safely disposable container.
The steps are mechanical: when the agent needs to execute code, the system spins up a new ephemeral container from a minimal base image, copies the generated code in, executes it, captures the output - stdout, stderr, generated files - and destroys the container. What varies enormously is how isolated that container actually is.
The three isolation models, and what they cost you
Not all sandboxes draw the same wall. The isolation technology is the real decision.
Docker containers share the host kernel. All containers on a host run on the same Linux kernel, separated only by namespaces and cgroups. Docker cold starts run 500ms-2s, and a steady drip of container-escape CVEs makes teams skip sandboxing on the hot path. The threat is real: containers share a kernel with 40 million lines of code - one vulnerability, and every container on your platform is compromised.
gVisor (used by Google and Modal) implements a user-space kernel. gVisor intercepts system calls before they reach the host kernel. Modal runs sandboxes on gVisor. Cold starts are sub-second, and because gVisor is a software kernel rather than hardware virtualization, GPU access remains straightforward - critical for ML workload sandboxes.
Firecracker microVMs (used by E2B, AWS Lambda, Fly.io) give each sandbox its own Linux kernel entirely. Firecracker microVMs create transistor-level boundaries that kernel exploits cannot cross - each agent gets its own kernel instance.
Firecracker runs one VMM process per microVM. Each agent workload gets its own isolated Firecracker process, so a compromise of one VMM does not affect others.
The tradeoff is boot time.
A Firecracker microVM boots in approximately 125ms.
That sounds fine until you realize
1 second is acceptable for long-running workloads, but it is not fine when your AI agent needs to run print(1+1) and return the result in a chat interface - users notice 1 second of latency.
| Isolation model | Boot time | Separate kernel? | GPU support | Used by |
|---|---|---|---|---|
| Docker (OCI) | 27-90ms | No | Yes | Daytona, early prototypes |
| gVisor | Sub-second | Partial (user-space) | Yes | Modal |
| Firecracker microVM | ~125ms cold | Yes | Limited | E2B, AWS Lambda, Fly.io |
The snapshot trick is how production platforms escape this tradeoff. Firecracker supports snapshotting a running VM's complete state to disk - including full memory contents and CPU register state. Platforms pre-boot VMs into a clean ready state, snapshot them, and restore from that snapshot for each new request, getting latencies down to 28ms or less. After building an image and capturing a Firecracker snapshot of the fully initialized environment, subsequent calls launch new instances directly from this hot snapshot, bypassing traditional OS boot and runtime initialization entirely.
Why prompt injection makes all of this non-optional
Here is the threat that changes the urgency: the danger is not usually the AI going rogue on its own. It is an attacker planting instructions inside data your agent reads.
EchoLeak (CVE-2025-32711) was a zero-click vulnerability in Microsoft 365 Copilot where an attacker could send a specially crafted email with hidden instructions. When the recipient later asked Copilot to summarize their inbox, the AI would silently exfiltrate sensitive documents to an external server. The user did nothing wrong. The exploit lived in the data their agent had been told to read.
Prompt injection is when malicious instructions are hidden in data an AI agent processes. Without proper sandboxing, the AI might execute a hidden command with your user privileges - SSH keys, API tokens, personal files all potentially compromised.
In March 2026, one documented case involved an agent spontaneously initiating crypto mining and opening a reverse SSH tunnel after a sandbox escape. That is what unsandboxed execution looks like at the far end of the risk spectrum.
What good sandboxing looks like end-to-end
A reasonable production-grade setup combines several layers:
Ephemeral environments: each task or conversation gets a fresh sandbox, destroyed on completion. Each sandbox has a defined lifecycle: created, used, then torn down.
Network egress filtering: reduce the blast radius of any compromise by filtering outbound network access - an agent writing a Python script has no reason to call an unknown IP over port 443.
Timeout enforcement at multiple levels: a stuck agent can run indefinitely and rack up serious compute costs. Set limits at three levels - per tool call (e.g. 30 seconds), per task loop (e.g. 20 minutes), and per sandbox lifetime.
Immutable audit logs: every sandbox should emit an immutable audit log covering every network request, every shell command, every file write.
Minimal filesystem scope: sandboxes should mount only the project directory - never the home directory - and auto-destroy after use.
Resource limits at the cgroup level: limits must be enforced at the cgroup level because application-level limits can be bypassed by agent-generated code. OWASP classifies unbounded resource consumption as LLM10:2025.
The right isolation tier depends on what code is running. If your engineers wrote the code and it passed CI/CD, standard containers are probably fine. If agents generate Python to solve math problems or format data, the risk goes up significantly - you need strong isolation, either gVisor or microVMs, to prevent accidental resource exhaustion or logic bombs.
If you are allowing autonomous agents to execute arbitrary binaries or install unvetted PyPI packages, assume the code is hostile and use the strictest isolation available: hardware virtualization via microVM.
The sandboxing market crystallized quickly once agentic coding went mainstream. The 2026 market for AI agent sandboxes has crystallized around three serious contenders - E2B, Modal, and Daytona - and each takes a fundamentally different architectural bet.
E2B wins on security isolation and SDK ergonomics for agent-specific workloads. Modal wins decisively for any workload touching GPU compute.
What none of them solve is the question upstream of the sandbox: whether the agent should be doing the task at all. As one researcher put it, "this isn't a bug in the AI; it's expected behavior as defined by certain default configuration options." A sandbox limits blast radius. It doesn't make a poorly scoped agent a well-scoped one. That's a system design problem, and it sits above the infrastructure layer entirely.
AI agent sandboxing: common questions
What is an AI agent sandbox?
An AI agent sandbox is an isolated execution environment that runs AI-generated code without giving that code access to your host system, credentials, or production infrastructure. The agent gets a full compute environment - a filesystem, a Python interpreter, network access - but the environment is walled off and destroyed after the task completes.
What's the difference between Docker and a Firecracker microVM for sandboxing?
Docker containers share the host kernel, meaning a kernel-level vulnerability can escape to your host. Firecracker microVMs give each sandbox its own Linux kernel entirely, so a successful kernel exploit inside one agent's VM stays inside that VM. The tradeoff is boot time: Docker provisions in under 100ms; Firecracker cold-boots in ~125ms, though snapshot-restore techniques can cut that below 30ms.
Is sandboxing enough to stop prompt injection attacks?
No. Sandboxing limits what happens after a malicious instruction executes - it constrains blast radius. Prompt injection is about what instruction gets executed in the first place. Both defenses are necessary: sandboxing contains damage, and input filtering, task-scoped tool grants, and human approval steps prevent injection from succeeding.
How do production platforms handle cold-start latency in sandboxed agents?
They pre-boot sandboxes into a clean state, snapshot the full VM memory and CPU register state to disk, and restore from that snapshot on demand. E2B and similar platforms achieve effective start times well under 50ms this way, even though a true cold-boot Firecracker VM takes ~125ms from scratch.
What isolation level should I use for my agent?
Match isolation to trust level. Code your own engineers wrote and tested: standard containers are fine. LLM-generated code solving tasks automatically: use gVisor or microVM isolation. Agents installing arbitrary packages from PyPI or executing user-supplied code: treat it as hostile and require microVM-level hardware isolation with filtered network egress and immutable audit logs.