A comprehensive guide to Codex CLI's TOML-based configuration system — covering config hierarchy, profiles, sandbox modes, and approval policies.
| ← Back to Codex CLI Best Practice |
Settings apply in order of precedence (highest to lowest):
| Priority | Location | Scope | Purpose |
|---|---|---|---|
| 1 | CLI flags / -c key=value |
Invocation | One-off overrides for a single run |
| 2 | .codex/config.toml |
Project | Team-shared defaults, profiles, MCP, agents |
| 3 | ~/.codex/config.toml |
Global | Personal defaults across projects |
# .codex/config.toml
model = "o4-mini"
sandbox_mode = "workspace-write"
approval_policy = "on-request"Named presets under [profiles.<name>] — switch with codex --profile <name>:
[profiles.conservative]
sandbox_mode = "read-only"
approval_policy = "untrusted"
[profiles.development]
sandbox_mode = "workspace-write"
approval_policy = "on-request"
[profiles.ci]
model = "o4-mini"
sandbox_mode = "read-only"
approval_policy = "never"
[profiles.trusted]
sandbox_mode = "danger-full-access"
approval_policy = "never"Set a default profile with profile = "conservative" at the top level.
| Mode | File Access | Network | Best for |
|---|---|---|---|
read-only |
Read-only project access | Blocked | Reviews, audits, CI analysis |
workspace-write |
Read/write inside the workspace | Blocked | Local development and doc/code edits |
danger-full-access |
Unrestricted filesystem access | Allowed | Fully trusted automation that needs network or installs |
| Policy | Behavior | Best for |
|---|---|---|
untrusted |
Auto-runs only trusted read-style commands; asks for the rest | New repos, audits, reviews |
on-request |
Model decides when it should ask | Everyday development |
never |
Never asks; failures come straight back to the model | Non-interactive runs and tightly controlled automation |
Use AGENTS.override.md for personal instruction overrides — loaded before AGENTS.md, not committed to git.
Declare shared integrations in the same config file:
[mcp_servers.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env = { GITHUB_TOKEN = "$GITHUB_TOKEN" }Register agents under [agents.<name>] and optionally point them at dedicated role files:
[agents.backend-dev]
description = "Handles backend implementation tasks"
config_file = "agents/backend-dev.toml"codex -c model=\"o3\" -c approval_policy=\"never\" exec "summarize this diff"- Using
danger-full-accessfor ordinary editing tasks - Treating
neveras a general-purpose local default - Using
danger-full-accessandnevertogether without a real containment boundary - Hardcoding secrets instead of using
$ENV_VARexpansion - Mixing unrelated concerns into one profile instead of creating focused profiles