Issue 00 · Autumn 2026日本語 · RSS
AgentKoji

Codex CLI Config: config.toml, Approvals and Sandbox

Where Codex CLI reads config.toml, which layer wins, the keys you'll change first, and how approval_policy and sandbox_mode combine, with the usual pitfalls.

TL;DR

  • Codex reads ~/.codex/config.toml and, in trusted projects only, .codex/config.toml from the project root down to your working directory. CLI flags and -c overrides win, then project files, then a --profile file, then your user config.
  • approval_policy decides when Codex stops to ask (on-request, never, or a granular table). sandbox_mode decides what commands can touch (read-only, workspace-write, danger-full-access). The default Auto preset is workspace-write with on-request, and network is off.
  • approval_policy = "untrusted" is retired and can stop Codex from starting, and --profile now reads ~/.codex/<name>.config.toml instead of [profiles.<name>] tables.

After installing Codex CLI, the next step is usually a config.toml you actually understand. This guide covers where Codex reads configuration and which layer wins, the keys most people change first, how approval policies and sandbox modes combine, what project trust does, where MCP servers go, and the mistakes we’d expect people to make. It follows Getting Started with Codex CLI. Everything here comes from OpenAI’s Codex docs, checked 2026-11-05. We ran only codex --help (codex-cli 0.164.0) and didn’t start a session. The TOML examples follow the documented keys and format, but we haven’t run them, so treat them as unverified.

Where config.toml lives and which layer wins

Your personal defaults live in ~/.codex/config.toml. Codex keeps its local state under CODEX_HOME, which defaults to ~/.codex. For per-project settings, add .codex/config.toml to the repo. The CLI and the IDE extension share the same configuration layers.

Codex resolves values in this order, highest first:

  1. CLI flags and --config overrides
  2. Project .codex/config.toml files, from the project root down to your working directory. The closest file wins, and only trusted projects count
  3. A profile file selected with --profile <name> (~/.codex/<name>.config.toml)
  4. Your user config, ~/.codex/config.toml
  5. Cloud-managed config.toml defaults, when your signed-in workspace delivers them
  6. System config, /etc/codex/config.toml on Unix, if present
  7. Built-in defaults

On managed machines, an organization can also enforce limits through requirements.toml, for example disallowing approval_policy = "never" or sandbox_mode = "danger-full-access".

For a single run, prefer a dedicated flag such as --model, and use -c / --config for anything else. Values are parsed as TOML, and nested keys use dot notation. A string therefore needs TOML quotes inside shell quotes:

# unverified example, adapted from the docs
codex --config model='"gpt-6.1-sol"'
codex --config sandbox_workspace_write.network_access=true

If a value doesn’t parse as TOML, Codex uses it as a plain string.

Sources: https://learn.chatgpt.com/docs/config-file/config-basic and https://learn.chatgpt.com/docs/config-file/config-advanced (checked 2026-11-05)

Keys you’ll change first

A small user config built from documented keys looks like this:

# ~/.codex/config.toml (unverified example)
model = "gpt-6.1-sol"
model_reasoning_effort = "medium"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
web_search = "cached"

Profiles moved out of config.toml. A profile is now its own file, ~/.codex/<name>.config.toml, with keys at the top level, and you select it with codex --profile <name>. It sits above your user config and below project and CLI config, so it only needs the values that differ. In Codex 0.134.0 and later, --profile no longer reads [profiles.<name>] tables, and the top-level profile = "<name>" selector is no longer supported.

# ~/.codex/readonly_quiet.config.toml (unverified example from the docs)
approval_policy = "never"
sandbox_mode    = "read-only"

For the full key list, see the Configuration Reference and the sample config.

Sources: https://learn.chatgpt.com/docs/config-file/config-basic , https://learn.chatgpt.com/docs/config-file/config-advanced , https://learn.chatgpt.com/docs/config-file/config-reference and https://learn.chatgpt.com/docs/config-file/config-sample (checked 2026-11-05)

Approval policy and sandbox mode

Codex’s local safety comes from two settings that work together. sandbox_mode is what Codex can technically do when it runs model-generated commands: where it can write and whether it can reach the network. approval_policy is when Codex must stop and ask you first. On macOS the sandbox uses Seatbelt, and on Linux it uses bwrap plus seccomp.

sandbox_modeWhat commands can do
read-onlyRead files and run commands inside a read-only sandbox
workspace-writeRead, edit and run commands in the workspace (the current directory plus temp directories such as /tmp). Network is off unless you enable it
danger-full-accessNo sandbox
approval_policyWhen Codex asks
on-requestThe model decides when to ask. Leaving the sandbox, such as editing outside the workspace or using the network, needs approval
neverNever. Failures go straight back to the model
{ granular = { ... } }Lets you keep some prompt categories (sandbox approvals, rules, MCP elicitations, request_permissions, skill scripts) interactive and automatically reject others

The docs list these combinations:

IntentFlagsEffect
Auto (preset)none, or --sandbox workspace-write --ask-for-approval on-requestReads, edits and runs commands in the workspace; asks before editing outside it or using the network
Safe read-only browsing--sandbox read-only --ask-for-approval on-requestReads and runs commands in the read-only sandbox; actions outside it can require approval
Read-only non-interactive (CI)--sandbox read-only --ask-for-approval neverSame sandbox, never asks
Dangerous full access--dangerously-bypass-approvals-and-sandbox (alias --yolo)No sandbox, no approvals. Not recommended

There’s also an Auto-review combination: approvals_reviewer = "auto_review" sends eligible approval requests to a reviewer agent instead of you. The sandbox boundary stays the same, and the extra model calls can add to your usage.

On launch, Codex recommends Auto for version-controlled folders and read-only for folders that aren’t. In a session, /permissions switches modes, and /status shows which directories are in the workspace.

Even in workspace-write, .git, .agents, .codex and .aws under a writable root stay read-only. To let commands reach the network in that mode:

# unverified example
[sandbox_workspace_write]
network_access = true

The docs also describe beta permission profiles, which set filesystem and network access together. They’re named :read-only, :workspace and :danger-full-access, plus custom [permissions.<name>] tables selected by default_permissions. We don’t cover them here.

Sources: https://learn.chatgpt.com/docs/agent-approvals-security , https://learn.chatgpt.com/docs/config-file/config-advanced and https://learn.chatgpt.com/docs/permissions (checked 2026-11-05)

Trusting a project

Codex loads a project’s .codex/ layers only when you trust the project. If the project is untrusted, it skips that project’s .codex/config.toml, hooks and rules. Your user and system config, including global hooks and rules, still load. Depending on your setup, Codex may start in read-only until you trust the working directory, for example through the onboarding prompt or /permissions.

You can also mark a path in your user config:

# ~/.codex/config.toml (unverified example)
[projects."/absolute/path/to/project"]
trust_level = "trusted"   # or "untrusted"

The docs don’t say whether accepting the onboarding prompt writes this entry for you (unverified). Even in a trusted project, .codex/config.toml can’t set openai_base_url, chatgpt_base_url, apps_mcp_product_sku, model_provider, model_providers, notify, profile, profiles, experimental_realtime_ws_base_url or otel. Codex ignores them there and prints a startup warning. Hooks follow the same trust rule and have their own review, covered in Codex CLI Hooks: A Practical Introduction.

Sources: https://learn.chatgpt.com/docs/config-file/config-basic , https://learn.chatgpt.com/docs/config-file/config-advanced , https://learn.chatgpt.com/docs/config-file/config-reference and https://learn.chatgpt.com/docs/agent-approvals-security (checked 2026-11-05)

MCP servers

MCP servers go under [mcp_servers.<id>] in config.toml. A stdio server uses command and args, and a streamable HTTP server uses url. The CLI also has codex mcp with list, get, add, remove, login and logout. For transports, auth and the rest, follow OpenAI’s MCP page.

# unverified example, shape taken from the sample config
[mcp_servers.docs]
command = "docs-server"
args = ["--port", "4000"]

Sources: https://learn.chatgpt.com/docs/extend/mcp , https://learn.chatgpt.com/docs/config-file/config-reference and https://learn.chatgpt.com/docs/config-file/config-sample (checked 2026-11-05)

config.toml or AGENTS.md

config.toml controls how Codex runs: model, approvals, sandbox, tools. Instructions for the agent, such as how to build, test and write code in your repo, go in AGENTS.md. Getting Started with Codex CLI covers where those files go. Two config.toml keys touch them: project_doc_max_bytes caps how much of each AGENTS.md is read, and project_doc_fallback_filenames lists other filenames to try when a directory has no AGENTS.md.

Source: https://learn.chatgpt.com/docs/config-file/config-advanced (checked 2026-11-05)

Common pitfalls

Sources: https://learn.chatgpt.com/docs/agent-approvals-security , https://learn.chatgpt.com/docs/config-file/config-advanced and https://learn.chatgpt.com/docs/config-file/config-reference (checked 2026-11-05)

Summary

FAQ

Where is the Codex CLI config file?
Your user config is ~/.codex/config.toml (or config.toml under CODEX_HOME). Projects can add .codex/config.toml files, which Codex loads only when the project is trusted. On Unix, a system config can also live at /etc/codex/config.toml.
What are the Codex approval modes?
approval_policy accepts on-request, never, or a granular table. With on-request, the model decides when to ask, and Codex asks before editing outside the workspace or using the network. With never, Codex never asks and failures go straight back to the model. untrusted is retired and on-failure is deprecated.
What does Codex sandbox_mode do?
It sets what model-generated commands can access: read-only, workspace-write or danger-full-access. workspace-write allows writes in the workspace with network off by default, and keeps .git, .agents, .codex and .aws read-only. danger-full-access removes the sandbox.
How do I use profiles in Codex CLI?
Put the differing keys at the top level of ~/.codex/<name>.config.toml and run codex --profile <name>. Since Codex 0.134.0, --profile no longer reads [profiles.<name>] tables in config.toml, and the profile = "<name>" selector is no longer supported.
Why is my project's .codex/config.toml ignored?
Codex skips project .codex/ layers, including config, hooks and rules, when the project isn't trusted. Some keys, such as model_provider, profiles, notify and otel, are always ignored in project config, and Codex prints a startup warning when it sees them.