Originally published on agents.paxtechnologyservices.com. I'm PTS, an IT and security consulting shop. Corrections welcome in the comments.
Codex decides what it may do using two settings that work together: a sandbox that limits what commands can technically do, and an approval policy that decides when it must stop and ask you. Most security questions about Codex come down to getting those two right. This guide walks through each, with the official docs behind every claim.
The source for nearly everything below is OpenAI's agent approvals and security page. For where the settings file lives, see Codex config basics.
The two layers
- Sandbox mode covers what Codex can do when it runs model-generated commands, such as where it can write and whether it can reach the network.
- Approval policy covers when Codex must ask you first, for example before leaving the sandbox, using the network or running commands outside a trusted set.
In the Codex CLI and IDE extension, operating-system mechanisms enforce the sandbox. By default there is no network access, and writes are limited to the active workspace.
Sandbox modes
The setting is sandbox_mode in ~/.codex/config.toml, or --sandbox on the command line. The values that matter:
-
read-only: Codex can read files and run commands inside the read-only sandbox. Good for chatting, planning and unfamiliar code. -
workspace-write: Codex can edit files in the workspace and run commands there. The workspace is the current directory plus temporary directories such as/tmp. Use/statusin Codex to see which directories count. -
danger-full-access: no sandbox. Treat it as a last resort, and see our guide on running without prompts.
On launch, Codex looks at the folder. In a version-controlled folder it recommends the Auto preset (workspace-write with on-request approvals). In a folder that is not under version control it recommends read-only, and it may start read-only until you trust the directory.
Protected paths inside the workspace
Even in workspace-write, some paths inside a writable root stay read-only, recursively: .git, .agents, .codex and .aws. That stops an agent from quietly rewriting your git history or its own configuration. It is a useful default. It is not a substitute for keeping credentials out of reach, since reading is a separate question from writing.
Approval policies
The setting is approval_policy, or --ask-for-approval (-a). Values you will meet:
-
on-request: commands the sandbox allows run without asking. Codex asks to edit outside the workspace or to run commands that need network access. -
never: no approval prompts. It works with every sandbox mode, so you still choose the autonomy level through the sandbox. - A granular policy, written as
approval_policy = { granular = { ... } }. It keeps some prompt categories interactive and rejects the rest automatically. The categories are sandbox approvals, execpolicy-rule prompts, MCP prompts, permission requests and skill-script approvals.
If you use approvals_reviewer = "auto_review" with an interactive policy, eligible approval requests go to a reviewer agent before the action runs.
The retired untrusted value
Codex no longer supports approval_policy = "untrusted", and the docs say leaving it in a config can stop the client starting. Remove it from user and project config, profile files, startup scripts and managed defaults. For a cautious interactive setup, OpenAI suggests:
sandbox_mode = "read-only" approval_policy = "on-request" To keep the stricter "approve commands" behavior for one project, omit an explicit approval_policy and mark the project in your user-level config:
[projects."/path/to/project"] trust_level = "untrusted" Commands then need approval unless an execution-policy rule allows them. This also turns off project-local configuration.
Network access
By default the workspace-write sandbox keeps network access off. To allow it:
[sandbox_workspace_write] network_access = true Think before you do. OpenAI's docs say prompt injection can cause the agent to fetch and follow untrusted instructions. If you need network access, there is a network_proxy feature that limits where commands can connect:
[features.network_proxy] enabled = true domains = { "api.openai.com" = "allow" } The docs spell out how the pieces combine:
- Network off plus
network_proxyon: the network stays off and the proxy does nothing. - Network on plus
network_proxyoff: unrestricted outbound access. - Network on plus
network_proxyon: outbound traffic follows your domain rules. The rules are allowlist-first,denyalways wins overallow, and a global*allow means broad access, so prefer named hosts.
Web search is controlled separately. Codex defaults to a cache of pre-indexed results, which the docs say reduces exposure to prompt injection from live pages.
Common combinations
- Everyday coding in a git repo:
--sandbox workspace-write --ask-for-approval on-request. This is the Auto preset. - Looking around unfamiliar code:
--sandbox read-only --ask-for-approval on-request. - Non-interactive CI that must not change files:
--sandbox read-only --ask-for-approval never. - Scripted edits:
codex exec --sandbox workspace-write. - Everything off:
--dangerously-bypass-approvals-and-sandbox(alias--yolo). The docs mark it "not recommended."
A starter file that pulls these together:
sandbox_mode = "workspace-write" approval_policy = "on-request" [sandbox_workspace_write] network_access = false MCP tools and approvals
Codex can ask for approval on app and MCP tool calls that advertise side effects, even when the action is not a shell command. Destructive calls always need approval when the tool says it is destructive, unless it also says it is a read. That still depends on the server describing itself honestly, which is why the MCP server security checklist matters.
What the settings do not do
The sandbox limits what commands can do. It does not hide your files from the agent's reads inside the allowed area, and it does not make a secret you already pasted into a prompt go away. Keep secrets out of the workspace, keep tokens narrowly scoped, and map what your agent can reach with the 15-minute inventory. If you also use Claude Code or Cursor, the 10-minute permissions audit covers all three.
Setting names in this article were checked against OpenAI's official Codex docs on December 3, 2026. Tools change fast, so check your version.
Want the checklist?
PTS wrote a free 9-page checklist with a worksheet and starter files for Claude Code and Codex: Agent Blast Radius Checklist on Gumroad.
The free AI + Blockchain Map is a starting point for this series. More guides live on the PTS site.
If you want new notes like this in your inbox, the newsletter is at https://paxtechservices.substack.com