---
title: "What is an agent sandbox? Isolating AI agent code"
description: "An agent sandbox is an isolated environment where an AI agent runs code and commands. Learn the isolation layers, from containers and gVisor to microVMs."
type: "glossary-term"
canonical_url: "https://theaiengineering.com/glossary/agent-sandbox"
markdown_url: "https://theaiengineering.com/glossary/agent-sandbox.md"
topic: "AI agents"
author: "The AI Engineering Editors"
publisher: "The AI Engineering"
updated: "2026-11-06"
keywords: ["Agent sandbox","code sandbox","code execution sandbox","sandboxed execution"]
citation: "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"
---

# What is an agent sandbox? Isolating AI agent code

Also called code sandbox, code execution sandbox, sandboxed execution.

> **Definition of Agent sandbox:** 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](https://theaiengineering.com/glossary/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](https://theaiengineering.com/glossary/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](https://github.com/google/gvisor) 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](https://firecracker-microvm.github.io/) 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](https://code.claude.com/docs/en/sandboxing) 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](https://learn.chatgpt.com/docs/sandboxing) offers `read-only`, `workspace-write`, and `danger-full-access` modes, 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](https://theaiengineering.com/glossary/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](https://theaiengineering.com/glossary/human-in-the-loop).

The [agent infrastructure directory](https://theaiengineering.com/platforms/agent-infrastructure) compares hosted sandboxes such as E2B, Daytona, Modal Sandboxes, and Vercel Sandbox, and the [AI coding agents comparison](https://theaiengineering.com/articles/ai-coding-agents) covers each agent's default protections.

## Related terms

- [AI agent](https://theaiengineering.com/glossary/ai-agent): An AI agent is a software system in which a large language model runs in a loop, calling tools, reading their results, and repeating until the task is complete or a stop condition is reached.
- [Prompt injection](https://theaiengineering.com/glossary/prompt-injection): Prompt injection is an attack in which text supplied to a large language model, typed by a user or hidden in content the model reads, alters the application's intended behavior or output.
- [Human-in-the-loop](https://theaiengineering.com/glossary/human-in-the-loop): Human-in-the-loop (HITL) is an agent design in which the run pauses at defined checkpoints, such as before a sensitive tool call, so a person can approve, edit, or reject the action.
- [Guardrails](https://theaiengineering.com/glossary/guardrails): Guardrails are programmatic checks placed around a large language model that validate, filter, or block inputs, outputs, and tool calls so an AI application stays within its safety, security, and policy limits.
- [Computer-use agent](https://theaiengineering.com/glossary/computer-use-agent): A computer-use agent is an AI agent that operates a graphical interface, such as a desktop or web browser, by reading screenshots and issuing mouse and keyboard actions instead of calling APIs.
- [MCP server](https://theaiengineering.com/glossary/mcp-server): An MCP server is a program that exposes tools, resources, and prompts to AI applications through the Model Context Protocol, running locally over stdio or remotely over Streamable HTTP.

## Guides that cover agent sandbox

- [AI coding agents: how they work and how the major tools compare](https://theaiengineering.com/articles/ai-coding-agents): AI coding agents compared: how they differ from autocomplete, the four main categories, a comparison table of major tools, and how to evaluate and secure them.
- [AI agent evaluation: metrics, graders, and how to test agents](https://theaiengineering.com/articles/ai-agent-evaluation): AI agent evaluation guide: measure task success, tool use, safety, cost, and pass^k reliability with code graders, LLM judges, eval sets from traces, and CI.
- [AI agent frameworks compared: LangGraph, CrewAI, ADK, and more](https://theaiengineering.com/articles/ai-agent-frameworks): An AI agent frameworks comparison of LangGraph, LangChain, CrewAI, the OpenAI, Claude, and Google SDKs, Pydantic AI, Mastra, and more, by language and license.
- [What are AI agents? How agents work and when to use one](https://theaiengineering.com/articles/what-are-ai-agents): AI agents are LLM systems that call tools in a loop until a task is done. Learn how the loop works, agents vs agentic AI, examples, failure modes, and limits.
- [What is the Model Context Protocol (MCP)? How it works](https://theaiengineering.com/articles/what-is-model-context-protocol): The Model Context Protocol (MCP) is an open standard for connecting AI apps to tools and data. Learn its architecture, transports, tool calls, and security.
- [A2A protocol vs MCP: differences and when to use each](https://theaiengineering.com/articles/a2a-vs-mcp): A2A protocol vs MCP: A2A connects AI agents to other agents, and MCP connects an agent to tools and data. Compare agent cards, tasks, transports, and security.
- [Claude Code vs Cursor: how the two coding agents differ](https://theaiengineering.com/articles/claude-code-vs-cursor): Claude Code vs Cursor compared: terminal agent vs AI editor, models, subagents, hooks, rules files, code review, CI use, pricing, and enterprise controls.

Part of the [AI agents](https://theaiengineering.com/topics/ai-agents) topic hub.

## 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: 2026-11-06
- URL: https://theaiengineering.com/glossary/agent-sandbox
- Markdown: https://theaiengineering.com/glossary/agent-sandbox.md
