AI agent sandboxing: isolating code and tools

Secure and govern
HoneyHive Engineering

AI agent sandboxing confines what an agent's code and tools can touch. The isolation layers, the limits to set and where sandboxes stop protecting you.

AI agent sandboxing means running an agent’s code and tool calls inside a boundary that limits what they can read, write, reach over the network and use as credentials. The boundary assumes the agent will sometimes do the wrong thing, whether from a bad instruction, a poisoned input or its own error, and makes sure the damage stays small. It is one layer of AI agent security, which covers the wider threat list; this page covers the isolation itself.

Why agents need one

An agent that runs shell commands or generated code can do whatever its process can do. OWASP’s AI Agent Security cheat sheet says not to “allow agents to execute arbitrary code without sandboxing,” and, for multi-agent setups, to isolate agent execution environments. The Kubernetes Agent Sandbox project frames the need the same way: autonomous agents generate and run untrusted code, so they need an isolated execution layer.

Four things to limit

A sandbox is a set of limits. The sources below cover four of them.

Limit What it means Example from the docs
Filesystem Where the agent can write, and what it can read Claude Code’s sandbox allows writes to the working directory and temp directory, and keeps settings, shell startup files and git hooks write-protected
Network Which hosts the agent’s code can reach In Claude Code on Linux, commands run in a separate network namespace and reach the outside only through a proxy that checks each hostname
Credentials Which secrets are visible inside Claude Code can deny reads of credential files and remove environment variables, or substitute a placeholder that the proxy swaps for the real value
Resources How much work a runaway agent can do OWASP says to enforce token, cost, retry and tool-chain limits

The protected paths are worth noticing. Claude Code’s docs explain that a command able to edit its own settings, .mcp.json or git hooks could grant itself permissions or add a hook that runs outside the sandbox. A sandbox that lets the agent rewrite its own rules is not a boundary.

Reads need the same care. By default that sandbox allows reading the whole computer except denied directories, including credential files, so you have to add the denials yourself.

Isolation layers, from light to heavy

The sources describe four ways to draw the boundary. They differ in what sits between the agent’s code and the host.

Layer How it isolates Documented in
OS process sandbox The operating system restricts one process and its children: Seatbelt on macOS, bubblewrap on Linux Claude Code, Codex
Container A dedicated container with minimal privileges Anthropic’s computer use docs
User-space kernel (gVisor) An application kernel that intercepts system calls and does not pass them to the host kernel; file access outside goes through a mediator gVisor, as a backend in Agent Sandbox
microVM or VM A lightweight virtual machine, run on KVM, with a minimal device model Firecracker; Kata Containers gives a dedicated kernel per sandbox

Heavier layers separate the agent from the host more completely. The costs the docs name are specific. gVisor trades some compatibility and per-call overhead for its isolation. Firecracker says its security depends on a well configured Linux host. The OS process sandboxes are the lightest, and Claude Code’s own docs say the sandbox reduces risk but is not a complete isolation boundary, and suggest running the whole Claude Code process in a container, VM or their sandbox runtime to put everything behind one boundary.

None of these pages ranks the layers for a given workload, so choose by what the agent runs. A coding agent working in your own repository with a human watching is a different case from a service executing code written by an untrusted user’s prompt.

Where a sandbox stops protecting you

Read the limits section of any sandbox’s docs. Claude Code’s lists several that apply broadly:

  • Scope. It covers shell commands only. Built-in file tools, local MCP servers and hooks run outside it. A tool the agent calls through MCP is only as contained as the server that runs it.
  • Hostname filtering. The default proxy filters by requested hostname and does not inspect TLS traffic, so an allowed host is trusted with whatever the agent sends it.
  • Escape hatches. Excluded commands and retries with the sandbox off run unsandboxed, and enabling nested user namespaces turns off a security boundary.
  • Off by default. Claude Code’s sandbox is off until you enable it, and native Windows runs commands unsandboxed.

Codex has a matching escape: its danger-full-access mode runs without sandbox restrictions.

Sandbox plus permissions

A sandbox answers what the agent can do. Permissions and approvals answer when it may. Codex’s docs separate the two: the sandbox defines technical boundaries, and an approval policy such as on-request lets the agent work inside the sandbox and ask when it needs to go beyond it. Automatic review of approval requests does not change the sandbox boundary.

That split is useful in practice. Routine actions inside the boundary need no prompt, so people are not trained to click through approvals, and the actions that cross it get a human decision. Anthropic’s computer use docs pair both in one list: a dedicated VM or container, no sensitive data in reach, an allowlist for the network, and human confirmation for decisions with real-world consequences. For approvals see human-in-the-loop AI; for tool-level rules, AI agent guardrails; for who the agent acts as, AI agent identity.

Setting one up

A checklist drawn from the sources above:

  1. Run code and commands in the lightest layer that fits the threat, and put a container or VM around the whole agent process when it handles untrusted input.
  2. Start the network allowlist empty and add hosts as needed.
  3. Keep credentials out of the sandbox, or hand the agent placeholders.
  4. Write-protect the agent’s own configuration, hooks and tool definitions.
  5. Cap tokens, cost, retries and tool-chain depth.
  6. Keep the sandbox on by default, and treat any option that turns it off as a decision to review.
  7. Trace what ran inside it. Agent tracing records the tool calls and their outputs, so you can see what a sandbox blocked and what the agent tried.

For agents that drive a screen, the same limits apply to the VM or browser they control; see computer use agents. For the loop that executes tool calls, see agent harness.

Isolation does not make a hijacked agent behave. OWASP’s cheat sheet and Anthropic both treat the sandbox as one control among several, and Anthropic says its computer use precautions remain important even with prompt injection classifiers running. Pair it with defences against prompt injection and with the approvals above.

FAQ

What is an AI agent sandbox?

An isolated environment where an agent's code and commands run with limited access to files, network and credentials, so a mistake or a hijacked instruction harms only the sandbox. OWASP's agent cheat sheet lists allowing arbitrary code execution without sandboxing as something to avoid.

Is a container enough to sandbox an agent?

It depends on the threat. Anthropic's computer use docs suggest a dedicated virtual machine or container with minimal privileges. Kubernetes Agent Sandbox offers gVisor or Kata Containers underneath for stronger separation from the host.

What is the difference between a sandbox and permissions?

A sandbox is a technical boundary the operating system or hypervisor enforces. Permissions and approvals decide when the agent may act or must ask. OpenAI's Codex docs put it as: the sandbox defines technical boundaries, and the approval policy decides when the agent pauses.

Should a sandboxed agent have internet access?

Only to an allowlist. Anthropic's docs recommend limiting internet access to allowed domains, and Claude Code's sandbox starts with an empty domain allowlist.

Does a sandbox stop prompt injection?

No. It limits the damage after an injection succeeds. Anthropic says its computer use precautions remain important even with prompt injection classifiers on. See prompt injection.

Share