Codex sandbox and approvals: how far to trust the agent
The short answer. Codex controls what the agent can do with two independent dials. The sandbox (sandbox_mode) says where it can act: read-only, workspace-write or danger-full-access. The approval policy (approval_policy) says when it must stop and ask: on-request or never. The cautious combination, and the default for local work, is workspace-write plus on-request: the agent writes inside the working folder and asks permission when it must leave it. Widening permissions speeds the work up and removes the safety net; tightening them is safe but floods you with requests. The criterion for choosing is one question: what do I lose if the agent gets it wrong, and can I recover it? Part 3 of the OpenAI Codex series, with data from the documentation consulted on 30 October 2026.
Caveat. I describe the documentation, not a penetration test: I did not try to bypass the sandbox and I cannot guarantee that no flaws exist. A sandbox reduces damage, it does not erase it. I am not affiliated with OpenAI.
The two dials, with their exact names
The sandbox page lists the values of sandbox_mode in config.toml:
read-only: the agent inspects files but neither edits them nor runs commands without approval.workspace-write: it reads, edits inside the workspace and runs routine local commands within that boundary. The documentation calls it the default low-friction mode for local work.danger-full-access: no sandbox restrictions, so the filesystem and network boundaries are gone. The name is not accidental.
For approvals, the same page describes on-request (works inside the sandbox and asks when it must go beyond it) and never (never stops to ask). It adds that the untrusted value is no longer selectable. The settings panel then shows three readable shortcuts, which are simply combinations:
| Label | Combination | What it means |
|---|---|---|
| Ask for approval | workspace-write + on-request | Always asks before editing external files or using the internet |
| Approve for me | workspace-write + on-request, with automatic review | Asks only for actions detected as potentially unsafe |
| Full access | danger-full-access + never | No boundary, no questions |
You may notice that "Full access" can appear as "Disabled by requirements.toml": in an organisation an administrator can forbid it altogether. If you work at a company, check before writing an internal guide that recommends it.
What happens underneath: the operating system
The sandbox is not a promise from the model, it is an operating-system mechanism. According to the documentation: on macOS it uses Seatbelt, already built in; on Linux and WSL2 it requires bubblewrap (bwrap); on Windows, in PowerShell, it uses a native sandbox, in WSL2 the Linux one. The difference concerns you in two ways. First: if bwrap is missing or user namespaces are not enabled (containers, some hardened distributions), the sandbox does not start and you will have to choose between not working and lowering the protection level: choose to fix the environment, not to move to danger-full-access. Second: the guarantee depends on your platform's mechanism, so the same profile is not demonstrably identical on three systems.
The network: the point the documentation leaves open
Here I am honest about a limit of the source. The page does not state the default network setting for local workspace-write. It does state that with danger-full-access internet access is unrestricted and that, in ChatGPT Work, the public network is off by default, with commands reaching only hosts on a managed allowlist. The settings show a toggle, "Allow network access in workspace write mode", and to extend the writable folders there is sandbox_workspace_write.writable_roots. To decide, do not rely on what you think the default is: open /status in your session and check, then try a harmless curl and see whether permission is requested.
Why does the network matter more than the filesystem? Because it is the exit channel. An agent that reads a web page or a file with hidden instructions (prompt injection) and has an open network can in theory send out what it finds in the environment. The defence is layered: network closed by default, no secrets in the session environment, and your attention when it reads external content (think of --search, part 2).
Environments and secrets
The configuration has a [shell_environment_policy] table with the key ignore_default_excludes and a [shell_environment_policy.filters] filter, which in the official example includes variables such as PATH and HOME. The point: you can decide which environment variables reach the commands the agent launches. The principle I draw from it, which is mine and not the documentation's, is to pass the minimum: if a work session does not need AWS_SECRET_ACCESS_KEY, it should not see it. The cost is a few "variable not found" errors to fix once; the benefit is that a wrong command cannot read a secret that is not there.
A decision matrix
My recommendation, derived from the question "what do I lose and can I recover it?":
| Situation | Sandbox + approval | Why |
|---|---|---|
| Reading an unfamiliar repository, exploring | read-only + on-request | Zero writes; exploring needs nothing more |
| Daily work on your own repo, clean Git | workspace-write + on-request | Changes sit in the diff and can be undone; exits ask permission |
| Many repetitive tasks, clean Git tree, network closed | workspace-write + "Approve for me" | Fewer interruptions, with automatic review of doubtful actions |
| Disposable machine or container without secrets | danger-full-access may be acceptable | You place the boundary outside (isolation, no secrets) |
| Your laptop with SSH keys and credentials | Never danger-full-access + never | One wrong command reaches everything |
The trade-off in the "Approve for me" row is real: automatic review is another model judging the request. It reduces interruptions but moves part of your decision onto a system that can be wrong; for commands touching production, read them yourself.
In non-interactive mode the defaults change
In part 6 we cover codex exec. Here is the point that concerns security: by default it runs in a read-only sandbox; to allow edits you pass --sandbox workspace-write. The documentation warns that --full-auto is no longer supported and proposes --sandbox workspace-write or --approve-for-me. If you find a script using --full-auto, it was written for an earlier version. And danger-full-access is to be used "only in a controlled environment, such as an isolated CI runner or a container".
Subagents, projects and trust
Two configuration details that affect security. Subagents inherit sandbox and approvals from the parent turn and cannot override sandbox_mode, approval_policy, model_provider or mcp_servers: permissions do not widen by delegating (part 7). And project configuration in .codex/config.toml is loaded only if you trust the project: opening a repository cloned from others does not automatically apply its rules to your agent. That is the right choice, and a reason to read someone else's repository before declaring it trusted.
A minimal practice, in five lines
- Clean Git tree and a commit before every session.
/statusat the start: check sandbox, approval and network.- Start from
workspace-write+on-request; widen one thing at a time and only for the task. - Read every approval request that leaves the folder: command, path, network destination.
- Review the diff and rerun the tests yourself before trusting.
What this page does not cover
In the page I consulted I did not find the list of protected paths inside a writable workspace (for example Git's configuration folders) or the default local network behaviour. Before relying on the sandbox to protect something specific, test it in a scratch repository: create a fake sensitive file, ask the agent to read and edit it, and observe what is allowed.
Sources (consulted 30 October 2026)
- Sandboxing (modes, approval policies, per-OS requirements).
- Security and administration (approval options, "Disabled by requirements.toml").
- Config basics (
shell_environment_policy, precedence, project configuration). - Non-interactive mode (
codex execdefaults). - Subagents (permission inheritance).
← Part 2: Codex CLI, first task Part 4: AGENTS.md and config.toml →
Commenti
Caricamento commenti...
Sign in to comment