When a coding agent runs a shell command, text a model generated becomes a process on a real machine, with your files, your network and often your credentials in reach. Most commands do what you asked. The risk is the rest: an agent that misread the task, or obeyed an instruction planted in an issue or a web page, can change files it should not touch, read your SSH keys and send them to an attacker's server. An agent sandbox is a safeguard for that case: a boundary the operating system or a virtual machine enforces around what those commands can touch, whatever the model decides. This chapter is about what a sandbox bounds, and what it cannot.

Thesis: An agent's blast radius has four parts: the files it can touch, the hosts it can talk to, the secrets it can hold and the systems it can act on. A sandbox bounds the first three for whatever runs inside it, regardless of what the model decides; identity and approvals bound the fourth. Not everything an agent does runs inside, so list what sits outside and bound that too. Size each part by the worst thing an allowed action could do with what is in reach, because prompts only ask, permissions decide what runs without a person, and the sandbox decides what exists for the commands that run inside it.

When Agents Need a Sandbox named the condition, an agent holding a person's full authority over live, shared things, and asked five questions. This chapter starts with what such an agent can reach. The renewals cleanup is set aside here; to show the boundary in its clearest case, this chapter sizes it for a coding agent in CI. The next shows why you must assume it will be misled; then come what it may do without asking, where its writes land, whom it acts as, and, last, checking what it did.

Why not let the model be careful instead? Because training and written rules work by persuading it, and the cases that hurt are the ones where text it read persuaded it of something else, the subject of Prompt Injection Is a Design Problem. That is why the bounds that matter are enforced by the harness and the operating system, never by the model.


Four Words First

  • Harness: the code around the model that calls it, runs the tools it asks for and feeds the results back, met in Model, Harness, Agent.
  • Sandbox: a boundary the operating system or a virtual machine enforces around what the agent's commands can touch. For a command that runs inside it, it holds no matter what the model asks for. In practice it is one of three things: rules the operating system applies to every command the agent runs (Claude Code and Codex use Seatbelt, built into macOS, and bubblewrap on Linux), a container, or a virtual machine. Later sections show how to choose.
  • Permission: a rule in the harness that decides whether a tool call runs on its own, asks a person first (an approval), or is refused.
  • Blast radius: everything a mistaken or misled agent could damage, given what it can reach and what it is allowed to do.

The difference between the middle two matters. A permission is checked before an action runs and judges it by the tool and the command or path it names. A sandbox is enforced while it runs and judges it by what it actually touches, so it holds even when an allowed command does more than its name says (Claude Code's sandboxing docs make the same distinction). A command called run-tests that also uploads your keys passes a permission check by name. It does not pass a sandbox with no route to the internet.

What a sandbox is not:

Not Why Where it is covered
A permission prompt A prompt is checked before a call, by its name; the sandbox is enforced while the command runs, by what it touches When Agents Need a Sandbox; Permissions Decide What Runs Unasked
A hook A hook judges a call before it runs and cannot see what the command then does Below, and Hooks Are a Channel, Not a Rule
A gateway A gateway limits only what crosses it, and is forced only when the network bound makes it the only way out Below
An identity A sealed sandbox holding a delete-capable token still deletes Below, and The Agent Acts for You, Not as You
A copy It decides what the agent can reach, not whether its writes land on the real files Let the Agent Work on a Copy
A check on the result Work done entirely inside the bounds can still be wrong Check the Work Before It Lands

The Four Parts of the Blast Radius

Files. Writing is the obvious risk, so harnesses confine writes, usually to the project folder and a temporary directory. Reading is the one people miss. Claude Code's sandbox, for one, lets commands read most of the machine by default, credential files such as ~/.ssh and ~/.aws/credentials included, and leaves protecting them to you. A boundary on writes alone still lets the agent read your keys. Writes carry a second risk, covered below: some files inside the project run later, outside the sandbox.

Network. Anything the agent can read, it can send, unless something stops it, so a sandbox needs both bounds: without the network bound a misled agent can send your keys out, and without the file bound it can escape the sandbox and reach the network anyway (Anthropic, on why it needs both). The usual design is an egress allowlist, the list of the only outside hosts the agent may send traffic to, enforced by a proxy, a relay every connection must pass through. Start the list empty. Know what the check does not do: web traffic is encrypted with TLS, and a proxy that does not decrypt it sees the host name, not the contents, so an allowed host is allowed for anything. A broad allowed domain is weaker still: Claude Code's sandboxing docs warn that because the proxy trusts the host name the client supplies, code inside can potentially use domain fronting or similar techniques to reach hosts that are not on the list. Two quieter routes use allowed paths too: data in the query string of a request to an allowed host, and, where the sandbox allows name lookups, a DNS query that carries whatever name the agent builds. The same rule covers any gateway you put in front of the agent's traffic: it sees and limits only what crosses it, so it is enforced only when the network bound makes it the only way out.

Secrets. The safest secret is one the agent never holds. A token in an environment variable (a named setting every process in the sandbox can read) can be printed or sent to any host you allowed. The better pattern keeps the real credential outside: commands inside see a placeholder, and the proxy swaps in the real value only on requests to approved hosts. OpenAI's sandbox security guide and Claude Code's sandboxing docs both document this shape; in Claude Code it depends on an experimental setting that lets the proxy decrypt traffic, and it protects only the credentials you list.

The systems it can act on. A sandbox bounds the machine, not the APIs the machine can reach. An agent holding a valid token for your customer-records (CRM) system, with delete rights, can delete customer records from a perfectly sealed sandbox. That part of the blast radius belongs to identity and permissions: the agent gets its own account, scoped to the task, and irreversible actions need a person. Confidence Is Not Consent sets the rule: an irreversible write is never automatic, at any confidence.

The four parts are separate controls, and closing one does not close the others. A sandbox that bounds only the file system covers the data the agent can read and write. Its tool calls, its network and the credentials it holds outside those files stay open, so it can still act as you.

How the Boundary Holds

"Whatever the model decides" is a claim about mechanism, so follow one command through it, with the sandbox turned on (Claude Code's is off until you enable it). A misled agent asks the harness to run a command that reads your private SSH key and posts it to a host it found in an issue.

  1. The harness starts the command inside the sandbox, as a new process the operating system has restricted before it runs a single instruction. On Linux, bubblewrap starts it with a view of the file system in which the paths you denied cannot be read and, by default, everything outside the project and a temporary directory is read-only, and with no route to the network except a relay to the proxy, which in Claude Code's design runs outside the sandbox. On macOS, Seatbelt attaches a profile that the kernel checks on every file the process opens and every connection it makes.
  2. The read. If you denied the key's directory, the read fails. No part of that decision reads the model's output.
  3. The send. The only connection the process can make is to the proxy, which checks the host against the allowlist and refuses one that is not on it.
  4. The result. The command fails, and the harness returns the error to the model as an ordinary tool result. The model may try another way; every other shell command meets the same kernel and the same proxy. Other ways around them remain: the harness's offer to retry a blocked command outside the sandbox (in Claude Code, turn it off with allowUnsandboxedCommands: false), any commands you excluded from it, and every tool that runs outside it, such as the harness's own file and web tools and its MCP tool servers, covered below.

That is what "enforced" means here: the decision is made by code that never reads the model's reasoning. It is also why defaults matter. With the sandbox on and its default read rules, step 2 succeeds, because reads of ~/.ssh are allowed until you deny them, and only the network bound stops the send.

How strong the sandbox itself must be depends on who else shares the machine. On a developer's own laptop, the operating system's process sandbox is usually enough. Usually enough for a misled agent, that is. The harness's sandbox is configured in settings the user, and so any code running as the user, can edit; against code already running as you, lock those settings centrally (Claude Code's managed settings, for one) or run the agent where your account is not. On a shared build host, give each job its own isolation. A container shares the host's kernel, the core of the operating system, so one bug in that kernel or in the container runtime is a way out, as the 2019 runc flaw (CVE-2019-5736) showed. gVisor puts its own kernel, running as an ordinary program, between the job and the host, so most system calls never reach the host's. A microVM, a lightweight virtual machine such as Firecracker, gives the job a whole kernel of its own behind a few emulated devices. Each shares less with the host than a container and costs more to run; between gVisor and a microVM it is a trade, not a ranking. The Agent Sandbox You Already Run compares these options, up to a full managed desktop, for agents that must drive desktop applications.

None of this is new. Unix's chroot (1979), FreeBSD jails (2000), the containers Docker made common in 2013, and gVisor and Firecracker (both 2018) are the same answer at different strengths. Saltzer and Schroeder's 1975 paper "The Protection of Information in Computer Systems" had already set out its rules: least privilege, fail-safe defaults and complete mediation, which is to check every access, not only the first.

What Sits Outside the Boundary

Say "the agent is sandboxed" and most people picture the whole agent inside the walls. In some harnesses' own sandboxes, it is just the shell commands. Claude Code's sandboxing docs (read 2026-11-14) say it plainly: "The sandbox covers shell commands only." Its built-in file and web tools follow permission rules instead, so a path you denied to the sandbox stays readable through the file-reading tool unless a permission rule denies it too, and local MCP servers, hooks and other helper processes "run with your full access". Others draw the line elsewhere: Codex's docs say its sandbox applies to built-in file operations as well as spawned commands, and Gemini CLI can sandbox its whole process, so check what yours covers.

What runs Inside the shell sandbox? What bounds it instead
Shell commands and the processes they start Yes The sandbox
The harness's built-in file and web tools No Permission rules, which match the tool and the path or domain
Local MCP servers, hooks and other helper processes No Their own credentials and your account: scope both, or run the whole harness in a container or VM
Files the agent writes that run later Written inside, run outside Review them as code

Two designs can close the gap. One runs every tool the agent calls in a separate sandbox, joined to the harness by one narrow channel, with the local shell and file tools switched off. Anthropic calls this decoupling the brain, "Claude and its harness", from the hands, "sandboxes and tools that perform actions", and gives the reason in its engineering write-up: in the coupled design, "any untrusted code that Claude generated was run in the same container as credentials". The bank's design below works this way. The other puts the whole harness inside a container or VM, as Claude Code's docs advise, and then the model's own host and key are one more allowed host and one more secret to keep at the proxy.

A hook, code the harness runs before a matching tool call, can allow the call, deny it and send the model the reason, ask a person, rewrite its input or add context for the model; it has no documented way to change which tool is called. If it errors or times out, the call goes on through the normal permission rules unless the hook, a command or HTTP hook, is configured to block on failure (Hooks Are a Channel, Not a Rule covers the placement). It is a checkpoint, not a wall: it judges a call before it runs and cannot see what a command does once it is running. The wall is still the sandbox.

Writes that run later. "Confined to the project folder" sounds safe until you list what in a project folder runs: git hooks, CI workflow files, package-manager scripts, build files, editor task settings. A write there is code that runs later, outside the sandbox, as the developer or as CI. Claude Code's sandbox denies writes to some of these even inside the project, among them hooks and config inside .git, the .vscode and .idea directories and shell startup files; its docs do not list CI workflow files or package scripts. Treat a change to anything that runs as a code change a person reviews, and run the pipelines for an agent's branches without secrets.

Time and money. The blast radius also has a size in compute: a runaway loop, a miner planted by an instruction, a cloud bill. Memory and CPU limits on the sandbox and a wall-clock cap on the task bound it.

Step 4 of 4

Local shell and file tools switched off

With the local shell and file tools switched off, every tool the agent calls runs in the separate sandbox.

Read this figure as text
  1. Just the shell commands In some harnesses' own sandboxes, only the shell commands run inside. The built-in file tools run outside it and follow permission rules instead.
  2. A separate sandbox One of two designs that can close the gap runs every tool the agent calls in a separate sandbox.
  3. One narrow channel That sandbox is joined to the harness by one narrow channel: tool calls go out through it, and their results come back.
  4. Local shell and file tools switched off With the local shell and file tools switched off, every tool the agent calls runs in the separate sandbox.

How Real Harnesses Do It

The widely used coding agents, among them Claude Code, OpenAI Codex and Gemini CLI, all document a sandbox, and as of November 2026 they disagree on the default: Codex sandboxes commands out of the box, Claude Code's docs say its sandbox is off by default, and Gemini CLI's describe theirs as something you enable. Defaults move, so check the one you rely on.

Two patterns repeat across all three. The sandbox and the approval are a pair: the sandbox makes most actions safe enough to run without asking, so the person can be asked mainly when the agent needs to step outside it. Anthropic reported in October 2025 that in its own use, sandboxing "safely reduces permission prompts by 84%." The pairing is not automatic. In Claude Code, for one, the sandbox itself approves a sandboxed command only in its auto-allow mode; in its regular mode the command still goes through the usual permission rules. And a command the sandbox blocks can be retried outside it, after a prompt or under a matching allow rule, unless allowUnsandboxedCommands is set to false. The second pattern is a switch: each tool keeps one that turns the boundaries or the prompts off; Claude Code's permissions docs, for one, say to use its switch only in an isolated container or VM. Read every such switch that way: turning off an inner boundary is safe only inside an outer one.


An Example: The Test-Fixing Agent in CI

Say a bank's platform team wants an agent to take the failing tests from its overnight continuous integration (CI) runs on a large repository and propose fixes. Here is the design, sized from the blast radius out.

On a developer's own laptop: The same read through the file-reading tool The file-reading tool follows permission rules, not the sandbox, so the denied path stays readable through it unless a permission rule denies it too. What can close this route is in What Sits Outside the Boundary.

Step 1 of 4

Failing test job queued

A failing test job from the bank's overnight CI runs is queued for an agent to propose a fix.

What a misled agent tries:

On a developer's own laptop:

Read this figure as text

The Test-Fixing Agent in CI

  1. Failing test job queued A failing test job from the bank's overnight CI runs is queued for an agent to propose a fix. The job waits in the queue.
  2. Fresh microVM per job Each job gets a fresh microVM of its own, because other teams' jobs run on the same build host. The microVM is drawn around the checkout, and the job moves down into it, to the agent.
  3. Git proxy adds the agent's token The agent never holds a git token: the git proxy, outside the microVM, adds one issued to the agent's own identity. The push leaves through the egress proxy and reaches the git proxy outside the microVM, where a violet ring marks the agent's token being added.
  4. Pull request The fix arrives as a pull request on an agent/* branch, and a person reviews and merges it. The push, still ringed in violet, moves into the pull request.

What a misled agent tries:

change files it should not touch

  1. change files it should not touch The agent can write only inside the checkout, so a write anywhere else is stopped at its edge. The attempt, drawn hollow, is stopped at the edge of the checkout.
  2. What still reaches a person What reaches a person is the pull request, and the sandbox does not bound it: the agent's own identity limits where it can push, and a person's review decides whether it merges. The stopped attempt stays faded where it stopped; the job's own push, ringed in violet, sits in the pull request.

read your SSH keys

  1. read your SSH keys No credentials are mounted in the microVM, so the read finds no keys to take. The attempt, drawn hollow, reaches the credentials slot and finds it empty.
  2. What still reaches a person What reaches a person is the pull request, and the sandbox does not bound it: the agent's own identity limits where it can push, and a person's review decides whether it merges. The stopped attempt stays faded where it stopped; the job's own push, ringed in violet, sits in the pull request.

send your keys out

  1. send your keys out Only the package mirror and the git host are reachable, so this connection is refused. A proxy that does not decrypt traffic sees only host names: an allowed host is allowed for anything. The attempt, drawn hollow, enters the egress proxy and is refused on its way out to the attacker's server.
  2. What still reaches a person What reaches a person is the pull request, and the sandbox does not bound it: the agent's own identity limits where it can push, and a person's review decides whether it merges. The stopped attempt stays faded where it stopped; the job's own push, ringed in violet, sits in the pull request.

read your SSH keys through the file-reading tool

  1. On a developer's own laptop The harness starts each shell command inside its own sandbox; with the key's directory denied, a command that reads your SSH key fails at the wall. The attempt, drawn hollow, starts inside the sandbox and is stopped at its wall, short of ~/.ssh.
  2. The same read through the file-reading tool The file-reading tool follows permission rules, not the sandbox, so the denied path stays readable through it unless a permission rule denies it too. What can close this route is in What Sits Outside the Boundary. The same attempt goes round the sandbox through the file-reading tool, shown in gold outside the walls, and reaches ~/.ssh, which is ringed.

The drawing, box by box

  • Failing test
    job queued
    • Fresh microVM
      per job
      • Writes: the checkout only
      • no credentials mounted
      • Egress proxy
        package mirror and git host only
        • package mirror
        • Git proxy adds the agent's token
          push to agent/* branches only
          • Pull request
            a person reviews and merges

On a developer's own laptop:

  • a developer's own laptop
    • agent
      • the sandbox
        shell commands
    • the file-reading tool
      bound by permission rules
    • ~/.ssh
      denied to the sandbox

Figure: The CI agent's sandbox. Each failing-test job gets a fresh microVM that can write only the checkout and holds no credentials, reaches only the package mirror and the git host through a proxy, and pushes through a git proxy to agent/* branches, where a person reviews and merges.

Each job gets a fresh microVM, because the build host also runs other teams' jobs. The agent can write only inside the checkout, and no credentials are mounted at all. Its traffic passes a proxy that reaches the internal package mirror and the git host and nothing else. It never holds a git token: a proxy outside the VM attaches one, issued to the agent's own identity, that can push only to branches named agent/*. A person reviews and merges. Shown in blue is what the sandbox bounds; in violet, what identity and a person bound. The two proxies also give the audit its record: every host contacted and every push, under an identity that is not a developer's.

The harness, which holds the model key and calls the model, runs outside the VM beside the proxies and sends every tool call, file tools included, into the VM to run, so nothing the agent runs can reach that key. One path still runs later. On most git hosts a push starts CI, which runs the pushed code outside the microVM, so the pipelines for agent/* branches get no deployment secrets.

Now the naive version: the same agent on a developer's laptop "just to try it," with that developer's cloud credentials in ~/.aws, a browser signed in to production consoles and open internet. Same model. Its blast radius is the developer's whole account.


When the Opposite Wins

An agent with no tools that act. A model that only reads approved documents and answers in a chat window runs nothing, so there is nothing to contain. Bound what it can read and stop there.

The strongest objection: a sandbox moves the risk rather than removing it. It does. A sealed container holding a delete-capable API token still deletes. The sandbox does nothing for the systems the agent is entitled to act on; identity and approvals carry that part. The answer is not to skip the sandbox but to stop asking it to do the other layers' work.

The cost objection is real too. A microVM per task adds start-up time and infrastructure to run, and for a developer working alone on code they own, the sandbox that ships with the harness is usually enough, and a VM per task is ceremony.

What to Do Next

  • Write down the blast radius of each agent you run: what it can write, read, send and change, and with whose credentials.
  • Bound reads, not only writes. Deny the credential directories explicitly, in the sandbox and in the permission rules for the harness's own file tools; Claude Code's sandbox, for one, can read them by default.
  • List what runs outside the sandbox: built-in file tools, MCP servers, hooks and the files in the project that run later. Bound each one, or put the whole harness in a VM. In Claude Code, set allowUnsandboxedCommands: false once the allowlist is right, and register any command or HTTP hook that carries policy to block when it fails.
  • Start the egress allowlist empty and add hosts as the work needs them, through a proxy you control.
  • Keep secrets and identity outside the sandbox. Swap credentials in at the proxy, and give the agent its own account scoped to the task.
  • Pair the sandbox with approvals, and turn an inner boundary off only inside an outer one you would happily throw away.

Next: every bound in this chapter assumes the agent can be talked into things. Prompt Injection Is a Design Problem shows how little that takes, and lets you try these four parts against one planted instruction.


Related reading: Prompt Injection Is a Design Problem on why an agent that reads untrusted text needs these bounds, The Agent Sandbox You Already Run for agents that must drive desktop applications, Confidence Is Not Consent on what may run without asking, Shadow AI Signs In as You on agents that act with a person's own identity, and Commands That Know When to Merge for keeping destructive and shared-state commands behind a person.