What is an agent sandbox? Isolating AI agent code
Also called code sandbox, code execution sandbox, sandboxed execution
Definition
An agent sandbox is an isolated execution environment in which an AI agent runs code, shell commands, or a browser, with enforced limits on the files, network hosts, and credentials it can reach.
An agent sandbox is an isolated environment in which an AI agent runs the code, shell commands, or browser sessions it generates. The sandbox limits which files the agent can read and write, which network hosts it can reach, and which credentials it can see. A model can be steered by prompt injection hidden in a web page, issue, or dependency, so the sandbox is the control that still holds when the model's judgment fails. Sandboxes also give agent evaluations a clean, seeded starting state for every trial.
How agent sandboxes isolate code#
Agent sandboxes isolate code at one of four layers, which differ in how much of the host kernel the agent's code can reach. Lighter layers start faster and cost less. Stronger layers put a second kernel between the code and the host, so an exploit has to break two layers before it reaches the host.
| Layer | Examples | Boundary |
|---|---|---|
| OS process sandbox | macOS Seatbelt, Linux bubblewrap | Kernel-enforced limits on one process tree on the developer's machine |
| Container | Docker and other OCI runtimes | Kernel namespaces separate processes that still share the host kernel |
| User-space kernel | gVisor (runsc) |
An application kernel intercepts system calls before they reach the host |
| MicroVM | Firecracker | A separate guest kernel behind a KVM hypervisor |
The gVisor project states the container problem plainly: a single shared kernel is efficient, but one vulnerability can allow a container escape. gVisor runs an application kernel written in Go that does not pass system calls through to the host. Firecracker uses KVM to create microVMs with five emulated devices and lists boot times under 125 ms with under 5 MiB of memory overhead per VM. Hosted sandboxes build on these layers; E2B's documentation, for example, states that every sandbox is a Firecracker microVM with its own kernel, not a container.
How coding agents sandbox file and network access#
Local coding agents such as Claude Code and Codex use operating system sandboxes instead of containers. They confine writes to the project workspace and filter network traffic, so a command the model chose cannot edit files elsewhere or send data to an arbitrary host. Defaults differ by product and version, so check them before a rollout.
- Claude Code. The sandboxed Bash tool uses Seatbelt on macOS and bubblewrap on Linux and WSL2, and it is off by default. When enabled, commands can write to the working directory, added directories, and the temp directory, and can read most of the machine, including credential files unless you deny them. Network traffic goes through a local proxy that checks each host against an allowlist that starts empty.
- OpenAI Codex. The Codex sandbox offers
read-only,workspace-write, anddanger-full-accessmodes, using Seatbelt on macOS and bubblewrap on Linux. Under the on-request approval policy, the agent works inside the sandbox and asks before going beyond it.
A sandbox limits what an action can affect, while guardrails inspect what goes into and comes out of the model. Actions the sandbox has to allow, such as a deploy or a payment, also need human approval.
The agent infrastructure directory compares hosted sandboxes such as E2B, Daytona, Modal Sandboxes, and Vercel Sandbox, and the AI coding agents comparison covers each agent's default protections.
Related terms
Guides that cover agent sandbox
- AI coding agents: how they work and how the major tools compare
- AI agent evaluation: metrics, graders, and how to test agents
- AI agent frameworks compared: LangGraph, CrewAI, ADK, and more
- What are AI agents? How agents work and when to use one
- What is the Model Context Protocol (MCP)? How it works
- A2A protocol vs MCP: differences and when to use each
- Claude Code vs Cursor: how the two coding agents differ
Cite this definition
The AI Engineering Editors. "What is an agent sandbox? Isolating AI agent code." The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/agent-sandbox
- Title
- What is an agent sandbox? Isolating AI agent code
- Author
- The AI Engineering Editors
- Publisher
- The AI Engineering
- Updated