Most developers turn on a local coding agent sandbox assuming the agent is boxed inside the current repository. Both OpenAI Codex and Claude Code do fence off filesystem writes to the workspace by default, and both still leave surprisingly wide surfaces open unless you explicitly lock them down.
In Claude Code, enabling the Bash sandbox restricts writes to the working directory and a per-user temp directory, while reads still cover most of the machine, including ~/.ssh and ~/.aws/credentials. The sandbox also wraps shell commands only. Built-in tools like Read, Edit, Write, WebFetch, and WebSearch, along with local MCP servers, hooks, and LSP servers, all run outside it. A sandbox.filesystem.denyRead rule does not stop the Read tool, and network.allowedDomains does not limit WebFetch. On top of that, if the sandbox fails its startup dependency check on Linux or WSL2, Claude Code falls back to running commands unsandboxed unless sandbox.failIfUnavailable is set to true.
OpenAI Codex has a similar split, plus two config traps in its newer [permissions] profiles. Under the default workspace-write mode (:workspace), protected directories inside a writable root like .git, .agents, .codex, and .aws are kept read-only, which blocks edits but still permits reads. If you switch to a custom [permissions.<name>] profile to deny disk reads outside the repo, any leftover sandbox_mode entry in a loaded config file or --sandbox CLI flag silently takes precedence and causes Codex to ignore default_permissions completely.
The second Codex trap is network filtering. Setting network.enabled = true and listing [permissions.<name>.network.domains] does not start the network proxy on its own. Without [features] network_proxy = true, commands get direct, unrestricted outbound network access and the domain allowlist is ignored. And just like Claude Code, Codex's command network proxy filters spawned local commands only; it does not filter MCP server connections, web search, connector tool calls, or browser activity.
For a Codex profile that blocks reads outside the workspace and enforces the domain allowlist (make sure no sandbox_mode key remains in config.toml):
default_permissions = "workspace-only"
[features]
network_proxy = true
[permissions.workspace-only]
extends = ":workspace"
[permissions.workspace-only.filesystem]
":root" = "deny"
":minimal" = "read"
[permissions.workspace-only.filesystem.":workspace_roots"]
"**/*.env" = "deny"
[permissions.workspace-only.network]
enabled = true
[permissions.workspace-only.network.domains]
"api.openai.com" = "allow"
One OS caveat on Linux, WSL, and Windows (MXC or elevated): Codex snapshots deny read globs like **/*.env when each sandboxed process starts. A long-running dev server or shell spawned inside the sandbox can still read a matching .env file created after that process started.
For Claude Code project settings (.claude/settings.json in the repo root, since . resolves to ~/.claude if you put this in user settings), pair denyRead with allowUnsandboxedCommands: false and failIfUnavailable: true (or use permissions.blockReadsOutsideWorkingDirectories), and mirror sensitive paths in permissions.deny so built-in Read cannot bypass the Bash sandbox:
{
"sandbox": {
"enabled": true,
"allowUnsandboxedCommands": false,
"failIfUnavailable": true,
"filesystem": {
"denyRead": ["~/"],
"allowRead": ["."]
}
}
}
Command-level OS sandboxes are useful for blocking accidental rm, stray writes, and raw curl calls from shell commands. Whenever an agent session also runs local MCP servers, hooks, or built-in web and file tools against untrusted repos or issues, those processes sit outside the shell sandbox, so putting the agent process itself inside a container or VM is the only way to enforce a single boundary across everything it spawns.