On Linux, Codex asks this every time it writes a file:
command failed; retry without sandbox?
Often with this warning at startup:
⚠ Codex's Linux sandbox uses bubblewrap and needs access to create user namespaces.
This does not happen on macOS. Per the official docs, macOS sandboxing works out of the box using the built-in Seatbelt framework. This is a Linux and WSL2 problem.
The cause [official]
The official documentation states that on Linux and WSL2 you must install bubblewrap with your package manager first. Codex uses the first bwrap executable it finds on PATH. Without it, Codex falls back to a bundled helper — and that requires unprivileged user namespace support.
Ubuntu 24.04 and later restrict exactly that by default through AppArmor. Hence the error.
The order the docs prescribe
1. Install bubblewrap
sudo apt install bubblewrap # Ubuntu / Debian
sudo dnf install bubblewrap # Fedora
2. On Ubuntu 24.04, load the extra AppArmor profile
sudo apt update
sudo apt install apparmor-profiles apparmor-utils
sudo install -m 0644 /usr/share/apparmor/extra-profiles/bwrap-userns-restrict /etc/apparmor.d/bwrap-userns-restrict
sudo apparmor_parser -r /etc/apparmor.d/bwrap-userns-restrict
3. Only if that fails — last resort
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
⚠️ The official docs label this a last resort. It is the one line that gets shared most in community answers, but it turns off a system-wide protection. Try step 2 first and reach for this only if step 2 does not work.
It may also be your version [community report]
Multiple users reported a regression starting at 0.118.0 where file writes fail on Linux:
- Working on
0.117.0, failing from0.118.0 - Writes via shell commands such as
sedsucceed, while the edit tool fails - Still reported on
0.120.0and0.121.0
An OpenAI maintainer replied that it should be fixed in 0.122.0 (2026-04-21). Check your version first:
codex --version
If you are on 0.118.0–0.121.0, upgrading alone may resolve it.
If you must stay on that version right now, this workaround was shared on the same issue. [community report · unconfirmed]
codex --enable use_legacy_landlock
Verifying
Restart Codex after changing anything and check that the startup warning is gone and edits go through without prompting. If the warning persists, confirm bwrap is on your PATH:
which bwrap
