A sandbox is a limit on what an AI agent can do that holds even when the agent is wrong, confused or manipulated. That is different from asking the model to be careful, or from showing a person a confirmation prompt. This guide explains what an agent sandbox covers, the main ways to build one, what two widely used coding agents do, and where sandboxes leak. It was checked on October 31, 2026 against the vendors' own documentation, and it does not rely on news reports of specific incidents.

What a sandbox is, and what it is not

Three questions define an agent sandbox.

A sandbox is not a permission prompt. A prompt asks a person; a sandbox constrains the process whether or not anyone is watching. The two work together. Anthropic's security documentation notes that a Bash command you approve can still write anywhere your user account can, and recommends turning on sandboxing to restrict Bash at the operating system level. OpenAI's Codex documentation draws the same line: the sandbox defines what Codex can technically do, and the approval policy defines when it must stop and ask.

Ways to isolate an agent

These options sit on a spectrum from light to heavy. Each trades convenience against how much stands between a compromised process and the host. The descriptions below are the projects' own.

None of these is automatically right. Code you generate and run on behalf of anonymous users needs a stronger boundary than a coding assistant working in your own repository.

What two coding agents actually do

Claude Code

Anthropic's documentation describes the Bash sandbox as an OS-enforced boundary around shell commands and the processes they start. It has two layers. For the filesystem, commands can write to the working directory and a temporary directory; reads are allowed across most of the machine unless denied, and the documentation says that includes credential files such as those under ~/.ssh and ~/.aws, so those need protecting by configuration. For the network, commands have no direct route out: connections go through a proxy on the machine that checks each host against a list of allowed domains, and the list starts empty.

The documentation is explicit about what the sandbox does not cover. File tools, MCP servers and hooks run outside it and follow permission rules instead. The sandbox is off by default. If it cannot start because of a missing dependency or an unsupported platform, commands run unsandboxed unless you set the option that makes Claude Code exit instead. Commands you list as excluded run with your full access. For sensitive work, Anthropic recommends running the whole process inside the sandbox runtime or a dev container, and using virtual machines for untrusted content.

OpenAI Codex

OpenAI's documentation says Codex runs locally with an OS-enforced sandbox, typically limiting it to the current workspace, plus an approval policy that controls when it must stop and ask. By default the agent runs with network access turned off. The documentation warns against modes that remove the sandbox and approvals, and warns that prompt injection can lead the agent to follow untrusted instructions, especially when web search or network access is enabled.

The pattern is the same in both: a narrow default, an explicit way to widen it, and a documented caution that the wider settings carry risk.

Where sandboxes leak

A sandbox is only as good as its configuration and its coverage. These are the common gaps, taken from the documentation above and from how the pieces fit together.

A practical checklist

Items marked (docs) follow behavior described in the vendor and project documentation above. Items marked (ours) are our own engineering recommendations.

Boundary

Configuration

Testing and operations

What this does not solve

A sandbox limits damage, not intent. The model can still be steered by text it reads, and anything the agent is allowed to do inside the boundary remains possible. That is why a sandbox belongs next to least-privilege access, defences against prompt injection and review of risky actions. For the broader list, see our AI agent security checklist and our explainer on identity and access management for AI agents.

How we approach this

When we build agents that run code or use tools, we begin with the question of what the worst thing the agent could do inside its boundary would be, and we shrink the boundary until that is acceptable. Then we test the boundary directly, not only the agent. If you want an outside review of how an agent is contained, that is part of our AI governance and security work.

Sources: Claude Code, sandboxing, Claude Code, security, OpenAI Codex, agent approvals and security, Docker Engine security, gVisor documentation, Firecracker, OWASP Top 10 for LLM Applications. All read October 31, 2026. Vendor settings change often, so check the current pages before configuring.