Sandbox for an AI agent: the options compared for Mac users
A sandbox for an AI agent is a fence the operating system builds around the commands the agent runs. On a Mac, Claude Code, Cursor, Codex and Gemini CLI, Google's coding agent, can all use the built-in macOS mechanism called Seatbelt. They differ in what the fence allows by default. Claude Code's sandbox is off until you turn it on. For runs without prompts, Anthropic's docs list isolated containers and VMs, not the sandbox alone.
You run a coding agent on the Mac where your SSH keys, browser sessions and projects live. A sandbox is what keeps its mistakes, and the mistakes of whatever it reads, from reaching all of that. This page compares the options and sends you to the page for each agent.
01What a sandbox for an AI agent is
A sandbox is a fenced area. A program inside it can touch only what the fence allows, even when it wants more. For agents the fence surrounds the risky operations. Gemini CLI's docs put it this way: sandboxing isolates potentially dangerous operations, such as shell commands or file modifications, from your host system, as a security barrier between AI operations and your environment.
A good fence is enforced by the operating system, so it holds whatever the model chose to run. It also covers files and network. Without the network side, a compromised agent could send out sensitive files such as SSH keys.
02The four agents compared
| Claude Code | Cursor | Codex | Gemini CLI | |
|---|---|---|---|---|
| On a Mac, built on | Seatbelt | Seatbelt through sandbox-exec | Seatbelt | sandbox-exec |
| Writes | Working directory, temp dir, added directories | Workspace, with protected paths like .git/hooks | Edits inside the workspace in workspace-write mode | Project directory only, in the default profile |
| Reads | Whole computer except denied directories, credential files included | Outside the workspace allowed by default | Can read files; edits stay in the workspace in workspace-write mode | Broad file reads in the default profile |
| Network | Through a proxy, allowed domains start empty | Closed until your network mode opens it; the default mode opens package-manager hosts | Off by default | Broad access in the default profile |
| Can a command get past the wall? | Retry with dangerouslyDisableSandbox | Rerun outside the wall, reviewed by a classifier | The approval policy decides when to go beyond the boundary | — (for a tighter wall, use the strict-proxied profile: reads and writes restricted, network through a proxy) |
Read the table row by row. The network row differs most. Codex starts with the network off. Cursor starts closed too, but its default mode then opens package-manager hosts. Claude Code's sandbox is off until you turn it on, and once it is on, its allowed list starts empty. Gemini's default profile, called permissive-open, starts from "deny everything" and then opens two things wide: you can read almost any file and use the network, while writes stay inside the project folder.
How you switch each one on also differs. Claude Code uses /sandbox or a sandbox.enabled setting. Gemini uses a command flag, an environment variable named GEMINI_SANDBOX, or settings.json, in that order of precedence. Codex fences commands by default, and Cursor fences shell commands in its recommended Auto-review mode.
Per-agent detail: Claude Code sandbox, Cursor sandbox, Codex sandbox, and for Gemini the sandbox section of Gemini CLI YOLO mode.
03What none of them fully close
Claude Code, Cursor and Codex each have a deliberate way out, so do not read any fence as absolute.
Claude Code can retry a failed command outside its fence. That fence covers shell commands only, and file tools, MCP servers and hooks run outside it. Cursor can rerun a failed command outside the wall. Codex notes that project-defined MCP servers can run commands outside it. An MCP server is a helper program that gives the agent extra tools, and the project you open can define one.
Sandboxing reduces risk but is not a complete isolation boundary. Cursor describes its run modes as best-effort guardrails and not a hard security boundary.
There have also been outright escapes, fixed in updates. The advisories are listed on Claude Code security and Cursor security. Keep every agent updated.
04When a container or VM is the better fence
The built-in fences cover commands. A container or VM fences the whole agent process. A container is a lightweight isolated environment for running programs. A VM, or virtual machine, is a separate computer simulated inside yours.
For the no-prompt mode, Anthropic's docs say to use isolated environments like containers, VMs, or dev containers without internet access. OpenAI's docs say to avoid --dangerously-bypass-approvals-and-sandbox unless you are inside a dedicated sandbox VM. To fence the whole Claude Code process, use a dev container with its firewall script.
Gemini CLI can also use a container as its fence. Docker or Podman, a Docker alternative, must be installed and running. Codex has a Docker pattern for when its Linux sandbox cannot run.
Two pages handle the setup. Claude Code devcontainer covers Anthropic's reference container and the editor flow, and Claude Code in Docker covers Docker's own sandbox tool and a plain container. The same idea exists in the cloud. GitHub's Copilot cloud agent runs in an ephemeral, firewalled environment with automated security scanning, and Cursor's Cloud Agents run inside their own dedicated machine.
05Which fence for which job
| What you want | Use | Page |
|---|---|---|
| Fewer prompts on your own Mac, shell commands fenced | The agent's built-in sandbox | The per-agent pages above |
| The agent's file tools, MCP servers and hooks fenced as well | A dev container with firewall | Claude Code devcontainer |
| No prompts at all | A container or VM | dangerously-skip-permissions |
| Choosing which prompts to keep | Permission settings, not a sandbox | AI agent permissions |
06Which sandbox for an AI agent should you pick?
Pick the built-in fence of the agent you already use, switch it on, and keep the network side as narrow as the task allows. Pick a container or VM when you want no prompts or you open code you do not trust. Keep your own keys out of the fenced area in every case.
A sandbox limits what a command can touch; it doesn't show what already ran. A sandbox limits what a command can touch but does not tell you what ran; Artificial Immunity's free, open-source core watches agent sessions and program starts on your Mac and reports what it finds.
All sandboxing guides
FAQ
What is a sandbox for an AI agent?
It is a fenced area that isolates the agent's risky operations, such as shell commands and file changes, from your computer. Gemini CLI's docs call it a security barrier between AI operations and your environment.
Who are the big four AI agents?
For coding on a Mac, this page compares four: Claude Code, Cursor, Codex and Gemini CLI. Each has its own sandbox rules, and the table below sets them side by side.
What are the top three AI agents?
Claude Code, Cursor and Codex are the three that have their own sandbox pages on this site, linked below. Gemini CLI is in the same table.
What is a sandbox in ChatGPT?
This page covers local coding agents on your Mac. For Codex, the OpenAI agent that runs commands on your computer, the sandbox is an OS-enforced boundary with network access off by default.
Is a sandbox enough to run an agent without prompts?
No. Anthropic's docs say sandboxing reduces risk but is not a complete isolation boundary, and they list the no-prompt mode for isolated containers and VMs.
Do all four agents sandbox on macOS the same way?
They use the same kind of macOS mechanism, but defaults differ. Claude Code's sandbox is off by default, Codex and Cursor start with the network closed, and Gemini's default profile allows broad reads and network.