Codex permissions: the sandbox, approvals and rules in one place

Say what OpenAI’s Codex may do in its sandbox, what it should ask about and what it must never run. The builder writes config.toml and a rules file with prefix_rule entries for your toolchain, and tells you where a rule does more, or less, than it seems. No sign-up, and nothing leaves this page.

1Say what Codex may do

Start from
Your toolchains (pick any)

Sandbox: no rule, so the sandbox and the approval policy decide. Allow: runs outside the sandbox without asking. Ask: Codex asks you first. Never: refused.

  • Run the tests

    The test commands of the toolchains picked above. In the sandbox they run without asking.

  • Lint, build and type check

    Lint, build, type check and format.

  • Install packages

    Needs the network, and a new package runs its own install scripts.

  • Look at git changes and history

    git status, diff, log and show. They work in the sandbox.

  • Commit and switch branches

    git add, commit and switch. The sandbox keeps .git read-only, so these ask to leave it unless a rule says otherwise.

  • Push to the remote

    Anything pushed is seen by others and can start a deploy.

  • Throw away work or history

    Force pushes, hard resets and git clean. Spelled another way they slip past; see below.

  • Delete files with rm

    rm and rmdir. In the sandbox they reach only the project and temp folders.

  • Use curl and wget

    curl and wget can send your files anywhere once they reach the network.

  • Containers, clusters and cloud

    docker, kubectl, helm, terraform and the AWS, Google Cloud and Azure command lines.

  • Database command lines

    psql, mysql, sqlite3, mongosh and redis-cli: any query, including DROP.

  • Run as root with sudo

    Anything run with sudo.

Your own rules: deploy scripts, release commands, anything else

One command per line, written as you would type it. A rule covers the command with any words after it, so make deploy also covers make deploy prod.

2Save the two files

~/.codex/config.toml

~/.codex/rules/permissions.rules

No rule: the sandbox decides

  • Run the tests
  • Lint, build and type check
  • Look at git changes and history
  • Commit and switch branches
  • Delete files with rm

Outside the sandbox, no question

  • Nothing

Asks you first

  • Install packages
  • Push to the remote
  • Use curl and wget
  • Containers, clusters and cloud
  • Database command lines

Never runs

  • Throw away work or history
  • Run as root with sudo

Then ask Codex which rule a command meets:

codex execpolicy check --pretty --rules ~/.codex/rules/permissions.rules -- npm install

If config.toml already has these keys, replace them rather than adding a second copy: TOML refuses a key set twice. Rules files add up, so a new one beside default.rules is fine.

How Codex decides what runs

Codex runs commands in a sandbox and asks before it goes past it. Rules change that per command: a rule matches the start of a command word by word, and every rule that matches counts. The details are in Codex’s rules documentation and configuration reference, which this builder follows (checked 20 November 2026). Codex calls rules experimental, so check them again after an upgrade.

The three Codex settings that decide what runs without asking
OptionSettingWhat it decides
The sandboxSettingsandbox_modeWhat it decidesWhat a command can reach: read-only, this folder (workspace-write), or everything (danger-full-access).
The approval policySettingapproval_policyWhat it decidesWhether Codex may ask you before going past the sandbox: on-request at the desk, never in a run nobody watches.
RulesSettingprefix_rule(...)What it decidesPer command: allow (outside the sandbox, no question), prompt (ask first) or forbidden. The strictest matching rule wins.

What rules can’t do

  • They match words, not intent

    git push --force as a forbidden rule misses git push origin main --force, and forbidding rm doesn’t stop find . -delete. Protect the main branch on the server, where no spelling gets past.

  • Allow is wider than it looks

    An allowed command runs outside the sandbox. Allow npm test and every test file, and every package it loads, can read your SSH keys and reach the network. Leave work the sandbox can do to the sandbox.

  • Asking only works while you watch

    A prompt rule waits at the terminal. With approval_policy = "never" nobody is there to answer. Sending the command to your phone keeps an unattended run moving without allowing more.

Answer from anywhere

Tick the phone box above and each shell command waits in your VariantGate inbox: yes or no from email, Slack, Teams, Discord or a phone notification, with every answer kept on the record. Free for one person and 100 requests a month, with no card.

Questions

Which rule wins when several match a command?

Every rule that matches counts, and the strictest decision wins: forbidden, then prompt, then allow. The order in the file doesn't matter, and a longer, more specific rule doesn't beat a shorter one. So an allow rule for git push origin feature still asks when a prompt rule for git push exists.

Does an allow rule just skip the question?

No, it does more. Codex's rules documentation says allow runs the command outside the sandbox without prompting. That means your whole disk and the network. Tests, builds and git status already run in the workspace-write sandbox without asking, so they need no rule at all.

Where do Codex rules files go?

Your own rules go in ~/.codex/rules/, in any file ending in .rules; Codex reads them all at start-up. When you pick "always allow" in the terminal, Codex writes to ~/.codex/rules/default.rules, so the builder uses a file of its own beside it. A repository can carry .codex/rules/ too, but Codex reads it only once you trust that project.

What about commands chained with && or wrapped in bash -lc?

Codex splits bash -lc and similar scripts only when they are a plain chain of commands joined by &&, ||, ; or |. Each part is checked and the strictest result wins. A script with a redirect, $( ), a variable assignment, a glob or an if is judged as one bash -lc command, which your rules for npm or git don't match, so the sandbox and the approval policy decide it.

What happened to approval_policy = "untrusted"?

Codex no longer supports approval_policy = "untrusted", and on-failure is deprecated. The configuration reference says to use on-request for interactive runs and never for runs nobody watches. A granular table form exists too, for letting some kinds of question through and rejecting others.

Can I make these rules apply to the whole team?

Yes. An administrator's requirements.toml (in /etc/codex, delivered by device management, or set in the cloud by your ChatGPT workspace's admins) can limit the approval policies people may pick and add rules nobody can remove. Those managed rules can only prompt or forbid, never allow.

Is the network on in Codex's sandbox?

In workspace-write, commands can't reach the network unless [sandbox_workspace_write] network_access = true. Turning it on lets package installs work in the sandbox, but it lets every program out, not only the ones you had in mind.