# Codex config.toml: approvals, sandbox, and the rules they do not keep

> Source: <https://besydr.com/blog/codex-config-toml-guide>
> Published: 2026-12-05 00:00:00+00:00

**Recommendation:** Set approval_policy = "on-request" with sandbox_mode = "workspace-write" and keep network_access off, since the post measured 49 rule breaks in 128 Codex requests despite config-level controls.
More in the playbook "Working with AI coding agents": <https://wpnews.pro/playbooks/coding-agents>

# Codex config.toml: approvals, sandbox, and the rules they do not keep

Codex config.toml sets three things that shape every session: the model, the approval policy that decides when Codex stops to ask you, and the sandbox that decides what its commands may touch. None of the three holds a rule you stated in words. This post walks the file, the settings that matter, and the gap they leave: in [our Codex benchmark](https://besydr.com/blog/codex-benchmark-with-and-without-besydr), Codex broke rules from earlier sessions 49 times in 128 requests, and 3 times with Besydr, a program that runs beside the agent and learns from its sessions.

## Where the Codex config file lives

Codex reads user-level configuration from `~/.codex/config.toml`. A project can add overrides in `.codex/config.toml`, and for security Codex loads a project's `.codex/` layers only when you trust the project. The CLI and the IDE extension share the same layers. The [config basics](https://developers.openai.com/codex/config-basic) page has the locations; the [full reference](https://developers.openai.com/codex/config-reference) lists every key.

## An annotated config.toml

A minimal Codex CLI config that keeps the default posture explicit:

```
# ~/.codex/config.toml
# model = "..."                 # set the model your account serves
approval_policy = "on-request"  # when Codex pauses to ask you
sandbox_mode = "workspace-write" # what its commands may touch

# Network is off inside the sandbox by default. To allow it:
# [sandbox_workspace_write]
# network_access = true
```

The file also picks the model and provider; the [config reference](https://developers.openai.com/codex/config-reference) lists the keys. The two settings shown are the core safety controls of the file, and they answer different questions.

## Approval policy

The Codex approval policy decides when the agent pauses for a human before running a command:

- `on-request` : commands the sandbox allows run without approval; Codex asks when it wants to go beyond the sandbox, such as editing outside the workspace or reaching the network.
- `never` : no approval prompts at all. This is what running Codex "full auto" means in practice: the agent works without asking, and the sandbox still decides what it can do. The flag form is`--ask-for-approval never` or`-a never` , and it combines with every sandbox mode.
- A granular table, `approval_policy = { granular = { ... } }` , keeps some prompt categories interactive while automatically rejecting others.

One migration note: `approval_policy = "untrusted"` is retired and can prevent Codex from starting. The [approvals and security page](https://developers.openai.com/codex/agent-approvals-security) gives the replacement: `sandbox_mode = "read-only"` with `approval_policy = "on-request"` for interactive read-only use, or a per-project entry that preserves the stricter command-approval rule.

## Sandbox modes

The Codex sandbox is an OS-enforced limit on what executed commands can touch, independent of approvals:

| Mode | What commands may do | 
|---|---|
| `read-only` | Read files; no writes | 
| `workspace-write` | Read and write inside the workspace; edits outside it need approval | 
| `danger-full-access` | No sandbox limits | 

Even in `workspace-write`, protected paths stay read-only: `.git` (including a pointer file's resolved git directory), `.agents`, `.codex` and `.aws`, recursively. Network access is off by default in the sandbox; `sandbox_workspace_write.network_access` turns it on. Codex also supports named permission profiles — the built-ins are `:read-only`, `:workspace` and `:danger-full-access` — for reusable filesystem and network policies.

## Common combinations

The [documentation](https://developers.openai.com/codex/agent-approvals-security#common-sandbox-and-approval-combinations) names three postures:

| Intent | Flags or config | Effect | 
|---|---|---|
| Auto (the default preset) | no flags, or `--sandbox workspace-write --ask-for-approval on-request` | Reads, edits and commands in the workspace; approval outside it or for network | 
| Safe read-only browsing | `--sandbox read-only --ask-for-approval on-request` | Reads and read-only commands; anything beyond can require approval | 
| Full access | `--sandbox danger-full-access` , or`--dangerously-bypass-approvals-and-sandbox` | Reads, edits, commands and network without prompts | 

Pick the posture per task, not per machine: read-only for exploring an unfamiliar repository, the Auto preset for work you review, full access only where a container is the boundary.

## What none of these settings does

A sandbox answers "may this command touch that file". An approval policy answers "must it ask first". Neither answers "is this what the developer asked for". Codex rules you state in words live in AGENTS.md or in chat, and the [Codex benchmark](https://besydr.com/blog/codex-benchmark-with-and-without-besydr) measured what happens to them: they are advice, and advice decays across sessions.

| Of 128 requests, five projects | Codex alone | With Besydr | 
|---|---|---|
| Rules from an earlier session broken | 49 | 3 | 
| Corrections the developer typed | 60 | 25 | 

The config file cannot close that gap because it has no key for your sentences. A study of 20,574 coding-agent sessions ([Tang et al., EMNLP 2026](https://arxiv.org/abs/2605.29442)) found constraint violations in 49.49% of pushback episodes in CLI sessions — the kind of session Codex runs.

Besydr closes the gap in two ways. It learns rules from your corrections and repeats them in later requests; the benchmark attributes the rule retention above to that learning. And it adds the missing check through Codex's own hooks: a call that conflicts with your words can be denied, with your sentence as the reason. Two honest limits from the [client documentation](https://besydr.com/docs/clients): Codex runs a hook only after you review and trust it in `/hooks`, and Codex's own documentation says its hooks are not a complete enforcement boundary, so a denied call is a strong default, not a guarantee. The [benchmark post](https://besydr.com/blog/codex-benchmark-with-and-without-besydr) has every number and the AGENTS.md details; the local program is free with octomind and needs a [licence](https://besydr.com/pricing) with Codex after a trial.

## Sources and method

- File locations, policies, sandbox modes and combinations: the [config basics](https://developers.openai.com/codex/config-basic) ,[config reference](https://developers.openai.com/codex/config-reference) and[approvals and security](https://developers.openai.com/codex/agent-approvals-security) pages, read 2026-11-29.
- The measured numbers come from [our Codex benchmark](https://besydr.com/blog/codex-benchmark-with-and-without-besydr) : five Python projects, two models, repeated runs.
- The study is [Tang et al., EMNLP 2026](https://arxiv.org/abs/2605.29442) ; its shares were read from Table 2.
- This post was drafted with AI assistance from these sources.
