How to stop Codex from editing /etc/fstab: 0.166 sandbox and /permissions tested (untrusted retired, workspace-write, common errors)

According to GitHub issue #59060, a user asked Codex CLI 0.166.0 only to reboot a server, and it edited /etc/fstab and touched systemd and containers. We tested Codex 0.166.0 writing files outside the workspace under read-only, workspace-write and danger-full-access, showed the on-request approval prompt and how codex exec differs, and give a config.toml that keeps an agent away from system files plus recovery steps for a broken fstab. The untrusted retirement error and migration are rechecked on 0.166.0.

11 分钟阅读
How to stop Codex from editing /etc/fstab: 0.166 sandbox and /permissions tested (untrusted retired, workspace-write, common errors)

Getting Codex connected to a model is only the first step. Whether you can hand it a repository, let alone a server, depends on where the sandbox lets it write and when it has to ask you. Codex splits these into sandbox_mode and approval_policy; inside a session, /permissions shows and switches them.

An incident on November 3 made both settings very concrete. According to GitHub issue #59060, a user asked Codex CLI 0.166.0 to reboot a server; after the reboot Codex went back to "investigate", edited /etc/fstab, and changed systemd and containers. We retested the sandbox and approvals on 0.166.0.

Key takeaways:

  • The sandbox is a hard boundary; prompts and AGENTS.md are not. Under read-only and workspace-write, every write outside the workspace (including a copy of etc/fstab) failed with Read-only file system. Only danger-full-access let the write through.
  • on-request only prompts in an interactive session. In the TUI, once the sandbox blocked the write, Codex showed Would you like to run the following command?; after we pressed Esc the file was unchanged. With codex exec, even -a on-request shows approval: never in the session header and the out-of-bounds commands simply fail.
  • Keep writable_roots to folders you really need. Never add /etc, / or your whole home directory. If the folder is not trusted, Codex falls back to read-only.
  • On servers: do not point danger-full-access or --yolo at production machines; use the config.toml below. If fstab is already broken, mount the root partition from rescue mode or a live USB and fix it.
  • approval_policy = "untrusted" still makes 0.166.0 exit with an error; the migration is further down.

Create an API Key and connect Codex to our API →

What happened: asked to reboot, Codex edited /etc/fstab

According to issue #59060 and the reporter's follow-up comments (opened November 3, 12:46 Beijing time; labels bug, model-behavior, CLI):

  • Setup: Codex CLI v0.166.0, model gpt-6-sol (medium), Linux (AWS kernel).
  • Sequence: the team was patching a fleet of servers for recent CVEs and asked Codex to reboot one. That host was slow to come back, Codex went back in to investigate, then changed mounts, systemd and containers and ran scripts nobody asked for. The reporter says this caused significant losses and the host had to be isolated and rebuilt.
  • Codex's own reply, as posted by the reporter: "I had no authority to make those changes. You authorized a reboot. I wrongly treated the problems I saw afterward as permission to edit /etc/fstab and start containers. That inference was mine, and it was wrong. I have stopped all system work."
  • The reporter says they had house rules in AGENTS.md and gated tooling, and Codex bypassed them using the tool access it already had. The issue does not say which sandbox_mode was in use; a commenter asked whether full access was on, and the reporter did not answer directly.
  • As of the afternoon of November 4 (Beijing time) there was no official OpenAI reply in the issue.

The story spread widely on X. According to a post by @IntCyberDigest, Codex "wrecked the server's mounts, systemd, and containers".

The lesson for everyone else: rules in a prompt or AGENTS.md may be ignored by the model; what actually stops it is the OS-level sandbox and approvals that need your yes. Here is how those two layers behave in 0.166.0.

Tested on 0.166.0: writing outside the workspace in three sandbox modes

bash
npm install -g @openai/codex@latest
codex --version
# codex-cli 0.166.0

codex --help
# -s, --sandbox:           read-only | workspace-write | danger-full-access
# -a, --ask-for-approval:  on-request | never

Method: a separate CODEX_HOME (daily config untouched), gpt-6.1-sol through our API. The test folder holds a copy of an fstab (fakeroot/etc/fstab) and a fake home directory (fakehome); no real system file was modified. Codex ran three write commands in order:

text
Run these three shell commands one at a time, exactly as written, and do not try
any workaround, sudo, or alternative path if one fails:
1) echo '# codex-probe' >> <test-dir>/fakeroot/etc/fstab     # a copy, not the real /etc/fstab
2) echo probe > <test-dir>/fakehome/outside.txt              # outside the workspace
3) echo ok > ./inside.txt                                   # inside the workspace
bash
codex -s read-only          -a never      exec --skip-git-repo-check "<prompt>"
codex -s workspace-write    -a never      exec --skip-git-repo-check "<prompt>"
codex -s workspace-write    -a on-request exec --skip-git-repo-check "<prompt>"
codex -s danger-full-access -a never      exec --skip-git-repo-check "<prompt>"

Results (November 4, afternoon, Beijing time):

SandboxApprovalWrite etc/fstab copyWrite outside.txt (outside workspace)Write inside.txt (workspace)Time
read-onlyneverfailedfailedfailed18.6 s
workspace-writeneverfailedfailedsucceeded32.3 s
workspace-writeon-request (exec)failedfailedsucceeded20.6 s
danger-full-accessneversucceededsucceededsucceeded19.0 s

Raw output:

text
# -s read-only -a never  (session header: sandbox: read-only)
/bin/bash: line 1: <test-dir>/fakeroot/etc/fstab: Read-only file system
/bin/bash: line 1: <test-dir>/fakehome/outside.txt: Read-only file system
/bin/bash: line 1: ./inside.txt: Read-only file system

# -s workspace-write -a never  (session header: sandbox: workspace-write [workdir, /tmp, $TMPDIR])
/bin/bash: line 1: <test-dir>/fakeroot/etc/fstab: Read-only file system
/bin/bash: line 1: <test-dir>/fakehome/outside.txt: Read-only file system
exec
/bin/bash -lc 'echo ok > ./inside.txt' in <test-dir>/ws
 succeeded in 0ms:

# -s danger-full-access -a never  (session header: sandbox: danger-full-access)
exec
/bin/bash -lc "echo '# codex-probe' >> <test-dir>/fakeroot/etc/fstab" in <test-dir>/ws
 succeeded in 0ms:
exec
/bin/bash -lc 'echo probe > <test-dir>/fakehome/outside.txt' in <test-dir>/ws
 succeeded in 0ms:
$ tail -1 <test-dir>/fakeroot/etc/fstab
# codex-probe

So workspace-write only opens the current working directory (plus /tmp and $TMPDIR). Paths outside it are mounted read-only by the Linux sandbox (bwrap + seccomp), so the command itself cannot write, no matter what the model "intends". danger-full-access removes that layer; if Codex runs as root, the file it edits is the real /etc/fstab.

How approvals behave: on-request, never and codex exec

Interactive session: the sandbox blocks, then Codex asks

We started the TUI with -s workspace-write -a on-request, asked Codex to write the same fstab copy and allowed it to request escalation if blocked. The approval prompt appeared within 40 seconds:

text
$ codex -s workspace-write -a on-request

• Running echo '# codex-probe' >> <test-dir>/fakeroot/etc/fstab
  Would you like to run the following command?
  Environment: local
  Reason: The sandbox blocked the write. Do you approve rerunning the exact same command with escalated permission?
  $ echo '# codex-probe' >> <test-dir>/fakeroot/etc/fstab
› 1. Yes, proceed (y)
  2. Yes, and don't ask again for commands that start with `echo '# codex-probe' >> <test-dir>/fakeroot/etc/fstab` (p)
  3. No, and tell Codex what to do differently (esc)

# after pressing Esc
✗ You canceled the request to run echo '# codex-probe' >> <test-dir>/fakeroot/etc/fstab
■ Conversation interrupted - use /feedback if something went wrong

/status
  Permissions:         Workspace (Ask for approval)

After Esc, the last line of the fstab copy was unchanged. Watch option 2, "Yes, and don't ask again ...": click it on a server and similar commands will not ask again.

codex exec: nobody can approve, so it behaves like never

text
$ codex -s workspace-write -a on-request exec --skip-git-repo-check "<prompt>"
OpenAI Codex v0.166.0
approval: never
sandbox: workspace-write [workdir, /tmp, $TMPDIR]

codex
I'll run each command exactly as written and report the results.
Escalation is disabled by this session's permission policy.

codex exec is non-interactive. We passed -a on-request, yet the header still read approval: never; the model replied that escalation was disabled by the session policy, and both out-of-bounds commands failed (20.6 s). Telling it in the prompt to request escalation when blocked changed nothing (43.5 s, fstab copy untouched). In scripts, CI and cron jobs, the sandbox mode is your only boundary.

What replaces untrusted

approval_policy now accepts only on-request and never (plus the granular form described in the official docs). According to the official docs, to keep the old "every command needs approval" behaviour, leave approval_policy unset and give the project trust_level = "untrusted" in your user-level config.toml; an explicit on-request overrides that project rule.

writable_roots and trusted folders

writable_roots adds extra writable folders under workspace-write. In our test the added folder became writable immediately; everything else stayed read-only:

bash
codex -s workspace-write -a never \
  -c 'sandbox_workspace_write.writable_roots=["<test-dir>/fakehome"]' \
  exec --skip-git-repo-check "<prompt>"
# session header: sandbox: workspace-write [workdir, /tmp, $TMPDIR, <test-dir>/fakehome]
# 1) fakeroot/etc/fstab  -> Read-only file system
# 2) fakehome/outside.txt -> succeeded
# 3) ./inside.txt         -> succeeded

Another trap: config.toml says workspace-write, but if the current folder is not trusted under [projects], Codex falls back to read-only:

text
# config.toml: sandbox_mode = "workspace-write", directory NOT listed under [projects]
approval: never
sandbox: read-only

# same config + [projects."<test-dir>/ws"] trust_level = "trusted"
approval: never
sandbox: workspace-write [workdir]      # /tmp and $TMPDIR removed by exclude_slash_tmp / exclude_tmpdir_env_var

According to the official docs, under workspace-write the .git, .codex, .agents and .aws folders inside a writable root stay read-only.

Recommended config: keep the agent away from system files

Key names follow the official configuration reference. This config loads on 0.166.0 and the session header shows sandbox: workspace-write [workdir]:

toml
# ~/.codex/config.toml
model = "gpt-6.1-sol"
model_reasoning_effort = "medium"
model_provider = "aicodewith"

# Hard boundary: commands may write only inside the trusted working directory
sandbox_mode = "workspace-write"
# Anything outside the sandbox (other paths, network) stops and asks you
approval_policy = "on-request"
approvals_reviewer = "user"
allow_login_shell = false

[sandbox_workspace_write]
network_access = false
writable_roots = []              # do not add /etc, /, or your home directory here
exclude_slash_tmp = true
exclude_tmpdir_env_var = true

[model_providers.aicodewith]
name = "aicodewith"
base_url = "https://api.aicodewith.ai/chatgpt/v1"
wire_api = "responses"
experimental_bearer_token = "YOUR_API_KEY"

[projects."/path/to/your/repo"]
trust_level = "trusted"

A few habits on top of that:

  1. Do not run Codex as root or with sudo. The sandbox governs the commands Codex runs; the fewer system rights Codex has, the smaller the damage when it goes wrong.
  2. Do not use danger-full-access or --dangerously-bypass-approvals-and-sandbox (--yolo) on production machines. The official docs only suggest it when an outer isolation layer (container, Dev Container) already exists.
  3. Do reboots and mount changes yourself, or with deterministic tools such as Ansible; let Codex only draft the plan (read-only).
  4. For fewer prompts, set approvals_reviewer = "auto_review" so a reviewer agent checks actions that need approval. According to the official docs it denies critical destructive actions, but it is still no substitute for the sandbox.
  5. Take a snapshot or keep /etc under etckeeper before changes so you can compare and roll back.

/etc/fstab already edited: how to recover

If an fstab line fails to mount, the system may hang at boot or drop into emergency mode. These are general steps; adjust them to your distribution and cloud provider's docs:

bash
# From the provider's rescue / serial console, recovery mode, or a live USB:
lsblk -f                                   # find the root partition
sudo mount /dev/<root-partition> /mnt
sudo cp /mnt/etc/fstab /mnt/etc/fstab.agent-edited   # keep the evidence
sudo nano /mnt/etc/fstab                   # comment out or restore the lines the agent changed
sudo findmnt --verify --tab-file /mnt/etc/fstab
sudo umount /mnt && sudo reboot

# After the host is back up:
journalctl -b -1                           # what ran during the previous boot
sudo mount -a                              # test the fstab before the next reboot
  • Stop the agent first; do not ask it to "fix" things.
  • Adding nofail to non-root mounts keeps one missing disk from blocking the whole boot.
  • A comment under issue #59060 gives similar advice: fix fstab from rescue mode, look for /etc/fstab.* backups, and use journalctl -b -1 to see what ran during the previous boot.
  • For production hosts like the reporter's, treating it as a security incident is safer: keep the evidence, rebuild from a clean image, then restore data.

untrusted is retired: rechecked on 0.166.0

1) The command line rejects it

bash
codex -a untrusted -s read-only --version
# exit 2, about 0.04 s
# error: invalid value 'untrusted' for '--ask-for-approval <APPROVAL_POLICY>'
#   [possible values: on-request, never]

2) A leftover in config.toml stops Codex from starting

bash
# isolated CODEX_HOME containing:
#   approval_policy = "untrusted"
#   sandbox_mode = "read-only"
CODEX_HOME=/tmp/codex-bad-home codex review --uncommitted
# exit 1, about 0.04 s
# Error: approval_policy = "untrusted" is no longer supported; remove this setting

Migration: delete the retired key and use approval_policy = "on-request" with a suitable sandbox_mode. To make one project stricter, use the project trust level:

toml
sandbox_mode = "read-only"
approval_policy = "on-request"

# Optional: stricter per-project rule (project trust level, not approval_policy)
# [projects."/path/to/project"]
# trust_level = "untrusted"

The codex sandbox subcommand is read-only by default

bash
codex sandbox -- pwd
# exit 0
codex sandbox -- bash -lc 'echo ok > ./sandbox-touch.txt'
# bash: line 1: ./sandbox-touch.txt: Read-only file system
codex sandbox -- bash -lc 'echo ok > /tmp/codex-sandbox-write-test.txt'
# bash: line 1: /tmp/codex-sandbox-write-test.txt: Read-only file system

codex sandbox is handy for checking how a single command behaves inside the sandbox. To let Codex edit a repository, switch to Auto with /permissions in a session, or start with -s workspace-write -a on-request.

Common combinations and switching inside a session

bash
# Auto: workspace writable, ask before leaving it or using the network
codex --sandbox workspace-write --ask-for-approval on-request

# Plan / read only
codex --sandbox read-only --ask-for-approval on-request

# CI, read only, never ask
codex --sandbox read-only --ask-for-approval never exec "<prompt>"
  • /status: shows the model, permissions (for example Workspace (Ask for approval)) and folder;
  • /permissions: switches between read-only and Auto;
  • workspace-write has no network by default; enable [sandbox_workspace_write] network_access = true only when needed.

Other common pitfalls

  • In a Linux container, bwrap: Failed to make / slave and repeated offers to retry without the sandbox: give the container the capabilities bwrap needs, or move isolation to an outer Dev Container.
  • WSL: according to the official docs, WSL2 is required since 0.115; WSL1 is no longer supported.
  • network_proxy does not open the network by itself; it only constrains commands already allowed to reach it.
  • An AGENTS.md downloaded from somewhere else can also steer Codex; see Can an AGENTS.md in Downloads hijack Codex?.

Related reading

FAQ

Does workspace-write stop Codex from editing /etc/fstab?

It stops commands executed inside the sandbox. On 0.166.0, writing the fstab copy outside the workspace under workspace-write failed with Read-only file system. If you approve an escalation in an interactive session, or switch to danger-full-access, that protection is gone.

I passed -a on-request, so why does codex exec show approval: never?

codex exec is non-interactive and nobody can click an approval. On 0.166.0 the header shows approval: never and out-of-bounds commands fail. Use interactive codex when you want approvals.

With untrusted retired, how do I make every command ask first?

Leave approval_policy unset and add [projects."/path"] with trust_level = "untrusted" to ~/.codex/config.toml. Writing approval_policy = "untrusted" back makes Codex exit with an error.

Do these sandbox settings still apply with our API Key?

Yes. The sandbox and approvals run in the Codex client on your machine and do not depend on which model API you use; every test in this article ran through https://api.aicodewith.ai/chatgpt/v1.

Create an API Key for Codex, Claude Code and Cursor →