PTS security notes / Guides

Codex config.toml security settings explained: sandbox_mode, approval_policy and network access

By PTS · Published 2026-12-03 · Updated 2026-12-03 · Docs checked December 3, 2026

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

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:

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:

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:

toml
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:

toml
[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:

toml
[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:

toml
[features.network_proxy]
enabled = true
domains = { "api.openai.com" = "allow" }

The docs spell out how the pieces combine:

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

A starter file that pulls these together:

toml
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.

Get the free checklist

A 9-page worksheet plus starter files for Claude Code and Codex. Download it on Gumroad. This site does not collect email.

Get the free checklist

Or get both free guides in one checkout.

Keep reading