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.
- 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:
- CLI flags and
--configoverrides - Project
.codex/config.tomlfiles, from the project root down to your working directory. The closest file wins, and only trusted projects count - A profile file selected with
--profile <name>(~/.codex/<name>.config.toml) - Your user config,
~/.codex/config.toml - Cloud-managed
config.tomldefaults, when your signed-in workspace delivers them - System config,
/etc/codex/config.tomlon Unix, if present - 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"
model: the default model in the CLI and IDE. The docs’ example,gpt-6.1-sol, needs access on your account or workspace, so pick one you can usemodel_reasoning_effort: how much reasoning the model applies, where supportedapproval_policyandsandbox_mode: covered in the next sectionweb_search:"cached"(the default) serves results from an OpenAI-maintained index instead of live pages."indexed"allows external access only when the search index gates it,"live"fetches current pages (same as--search), and"disabled"turns the tool off. With--yoloor another full-access setting, the default becomes live[features]: toggles optional features. For example,hooksis on by default
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_mode | What commands can do |
|---|---|
read-only | Read files and run commands inside a read-only sandbox |
workspace-write | Read, 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-access | No sandbox |
approval_policy | When Codex asks |
|---|---|
on-request | The model decides when to ask. Leaving the sandbox, such as editing outside the workspace or using the network, needs approval |
never | Never. 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:
| Intent | Flags | Effect |
|---|---|---|
| Auto (preset) | none, or --sandbox workspace-write --ask-for-approval on-request | Reads, 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-request | Reads 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 never | Same 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
approval_policy = "untrusted"is retired and can stop Codex from starting. Remove it from user and project config, profile files and startup scripts. For the stricter command approvals, the docs suggest atrust_level = "untrusted"project entry instead.on-failureis deprecated- An old
[profiles.<name>]table orprofile = "<name>"line does nothing on 0.134.0 and later. Move it into~/.codex/<name>.config.toml - Project settings that don’t apply usually mean the project isn’t trusted, or the key is one that project config ignores
- A string passed with
-cneeds TOML quotes, as inmodel='"gpt-6.1-sol"' - Commands can’t reach the network in
workspace-writeuntil you setsandbox_workspace_write.network_access = true - Inside Docker, the Linux sandbox may fail if the container blocks namespaces, setuid
bwraporseccomp. The docs suggest making the container your isolation and running--sandbox danger-full-accessinside it
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
- User config is
~/.codex/config.toml. Project.codex/config.tomlfiles load only in trusted projects - Precedence: CLI flags and
-c, then project files (closest wins), then a--profilefile, then user config sandbox_modesets what commands can touch, andapproval_policysets when Codex asks. Auto isworkspace-writewithon-request, with network off.git,.agents,.codexand.awsstay read-only even inworkspace-write- Profiles are
~/.codex/<name>.config.tomlfiles, not[profiles]tables approval_policy = "untrusted"is retired. Remove it- Put MCP servers under
[mcp_servers.<id>], and agent instructions inAGENTS.md
Related articles
- Getting Started with Codex CLI
- Codex CLI Hooks: A Practical Introduction
- Claude Code Permissions and settings.json: A Cheat Sheet
- Claude Code vs Cursor vs Codex: What Differs in Practice
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.