Codex config.toml: location, precedence and safe settings
Where Codex reads config.toml, which layer wins, how profiles and project trust work, and the keys that control sandbox, approvals and secrets.
Your personal Codex defaults live in ~/.codex/config.toml. A repo can add .codex/config.toml, and Codex loads it only when you trust the project. Command-line flags and -c overrides beat every file. The security-relevant keys are sandbox_mode, approval_policy, shell_environment_policy, history.persistence and projects.<path>.trust_level.
Precedence
The config docs list these layers, highest first.
- CLI flags and
--configoverrides - Project
.codex/config.tomlfiles, from the project root down to your current directory, with the closest file winning - A profile file chosen with
--profile - User config at
~/.codex/config.toml - Cloud-managed
config.tomldefaults, when delivered for the signed-in workspace - System config at
/etc/codex/config.tomlon Unix - Built-in defaults
Administrators can also set managed requirements. The docs describe requirements.toml for managed hooks, and forced_login_method restricts sign-in to chatgpt or api.
Profiles
Profiles are separate files. The CLI reference says --profile (short form -p) layers $CODEX_HOME/<name>.config.toml on top of the base user config. Keep shared defaults in config.toml and put only the differences in a profile file, such as a stricter one for client work.
codex -p reviewProject trust
The docs say Codex loads project .codex/ layers only when you trust the project. For an untrusted project it skips project config, hooks and rules, while user and system config still load. You can record the decision in config.
[projects."/Users/you/work/repo"]
trust_level = "trusted"Allowed values are "trusted" and "untrusted". Trusting a repo lets its .codex/ files change how Codex behaves, so trust only code you have read.
Security-relevant keys
| Key | Values and meaning |
|---|---|
sandbox_mode | read-only, workspace-write, danger-full-access |
approval_policy | on-request, never or a granular table. untrusted is unsupported and on-failure is deprecated |
sandbox_workspace_write.network_access | Allows outbound network inside workspace-write |
sandbox_workspace_write.writable_roots | Extra writable folders |
default_permissions | A named permission profile. Do not combine with sandbox_mode |
shell_environment_policy.inherit | all, core or none for subprocess environment |
shell_environment_policy.ignore_default_excludes | Keeps variables containing KEY, SECRET or TOKEN out before other filters when true |
history.persistence | save-all or none |
cli_auth_credentials_store | file, keyring, auto, ephemeral |
allow_login_shell | Boolean. When false, login-shell requests are rejected |
features.hooks | Turns lifecycle hooks on or off |
A cautious starting file
sandbox_mode = "workspace-write"
approval_policy = "on-request"
[shell_environment_policy]
inherit = "core"
[history]
persistence = "save-all"Setting persistence = "none" stops local transcript saving, which also removes your record of what the agent did. Think about that trade before you use it. The sandbox keys are explained in Codex sandbox.
One-off overrides
Use -c key=value for a single run. The installed help for Codex CLI 0.166.0 says the value is parsed as TOML and falls back to a literal string if it does not parse. The same help lists --strict-config, which errors on fields this version does not recognize. That catches a typo that would otherwise leave a setting silently unset.
codex --strict-config -c 'sandbox_mode="read-only"'Check the result
Codex 0.166.0 includes codex doctor, which diagnoses local installation, config, auth and runtime health. Run it after editing config, and use /status in a session to see the active directories. Do not commit a user config that contains tokens. Credentials belong in the credential store, as described in Codex API key.
Checked against the vendor documentation on November 25, 2026. Config basics · Config reference · Advanced config · CLI reference
See what the settings allowed
Excellent’s free scan reads supported logs on the Mac and reports findings for review. For a local report without installing an app, run the free scan. See a sample report. Excellent Pro can configure Codex’s native Mac sandbox from your file and folder rules, with a plan to review first. Sandbox setup · Pricing. Pro is US-only for now.


