apply_patch and managed sandbox fail with Bubblewrap loopback/userns errors on Ubuntu 24.04
Summary
apply_patch and ordinary managed sandbox commands fail before the requested command can run. The failure appears to come from Bubblewrap sandbox setup, not from repository file permissions.
Environment
- OS: Ubuntu 24.04
- Kernel: 6.17.0-35-generic
- Bubblewrap: 0.9.0
kernel.unprivileged_userns_clone = 1kernel.apparmor_restrict_unprivileged_userns = 1/usr/bin/bwrapis a normal executable, not setuid, with no file capabilities
No local usernames, workspace paths, repository paths, or secrets are included in this report.
Observed behavior
apply_patch fails before it can read a file in the configured writable workspace. The same sandbox failure can also occur for simple sandboxed commands such as id, uname, or which bwrap.
Error from apply_patch:
fs sandbox helper failed with status exit status: 1:
bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted
Minimal diagnostics
Outside the managed sandbox, Bubblewrap itself is present:
bubblewrap 0.9.0
Minimal Bubblewrap tests fail:
bwrap --ro-bind / / true
# bwrap: setting up uid map: Permission denied
bwrap --unshare-net --ro-bind / / true
# bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted
Expected behavior
apply_patch should be able to edit files under the configured writable workspace root, or Codex should provide a supported fallback edit path that still enforces workspace-write restrictions without requiring host-wide security changes.
Actual behavior
The file-edit path is unusable because the sandbox helper depends on Bubblewrap/user namespace/network namespace behavior blocked by the host security configuration.
Request
Please make the apply_patch / managed sandbox path robust on Ubuntu systems with AppArmor unprivileged user namespace restrictions, or provide a supported fallback that does not require changing host-wide sysctl/security settings.
Applied devbox recurrence — July 6, 2026
A Codex user on Applied devboxes reported that both apply_patch and general command execution became blocked after the local Bubblewrap sandbox could not read /proc/sys/kernel/overflowuid; /proc/sys/crypto/fips_enabled also returned an unexpected error. Codex escalated or used in-place editing fallbacks. Restarting the devbox restored operation, suggesting an unhealthy or disconnected proc mount rather than repository permissions.
Source: [https://openai.enterprise.slack.com/archives/C08MGJXUCUQ/p1783397892149239](<https://openai.enterprise.slack.com/archives/C08MGJXUCUQ/p1783397892149239>)
This is the same user-visible failure family—managed commands and apply_patch fail before the requested operation—but a different host-level trigger from the original loopback/user-namespace reproduction. Diagnostics should capture the Codex/CLI build, devbox image and kernel, mount namespace state, /proc mount health, the exact Bubblewrap command/error, and whether the failure began after a benchmark or sandbox lifecycle event. A restart is a recovery, not a fix.
11 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Adding severity/context: this is not just extra approval prompts.
When the managed sandbox hits this Bubblewrap/AppArmor failure, the coding workflow is effectively unusable:
apply_patch, the expected file-edit path, cannot read or update files inside the configured writable workspace.This is related to #29052 / #29043, but those are framed mostly as approval-prompt regressions. This issue is specifically that the supported sandboxed edit/tool path cannot function at all.
Additional datapoint: launch context appears to matter.
After starting Codex from the VS Code integrated terminal, managed
workspace-writeis currently working on the same machine/environment class:idsucceedsgit status --short --branchsucceedsapply_patchcan create and delete a scratch file successfullyEarlier failures with the same reported Bubblewrap error occurred under a different launch/session context. This suggests the issue may depend on how the Codex process/tool runner is launched or initialized, not only on the host OS settings.
I can reproduce a closely related bwrap loopback failure on another Ubuntu 24.04-family environment.
Environment
0.142.0Linux 6.17.0-29-genericbubblewrap 0.9.0/usr/bin/bwrapkernel.unprivileged_userns_clone = 1user.max_user_namespaces = 255645kernel.apparmor_restrict_unprivileged_userns = 1Minimal reproduction
Outside Codex, this fails with the same loopback error:
Result:
A related non-network probe also fails:
Result:
Codex behavior
Codex shell commands fail before the requested command body runs. This looks like a Codex CLI sandbox / bubblewrap / Ubuntu AppArmor interaction rather than a repository command failure.
Local workaround
I did not change OS AppArmor/sysctl settings, and I did not use
--dangerously-bypass-approvals-and-sandboxas a default.As a local workaround, I used an explicit opt-in profile:
Then launched Codex with:
With that opt-in profile, a nested
codex execthat ranpwdcompleted successfully.Suggestion
A
codex doctorpreflight check or a more actionable error message for this bwrap fingerprint would make this easier to diagnose without changing the default sandbox policy.I’m happy to look into a small diagnostic-only PR around
codex doctorif that direction sounds reasonable to the maintainers.I can reproduce the same class of issue in a Docker/devcontainer setup, and I think the impact is broader than just the initial
bwrapstartup failure.In my case, the core problem is that
apply_patchand normal workspace-confined edits are coupled to the Linuxbwrapsandbox. Whenbwrapcannot create namespaces inside the devcontainer, the agent cannot reliably perform normal approved workspace patches.Environment
workspace-writeon-requestdanger-full-accesskernel.unprivileged_userns_clone = 1Diagnostics inside the container:
apply_patchbehaviorapply_patchis inconsistent:Creating a new workspace file may succeed:
But deleting or updating an existing workspace file fails because the sandbox helper tries to read the file and hits
bwrap:Observed error:
This makes
apply_patchunusable for normal coding work, even though the target file is inside the writable workspace.Landlock workaround is not sufficient
I also tried:
This allowed:
But it is not a viable complete workaround. In the same setup, normal tool/shell execution can fail with:
So the available workaround is both deprecated and incompatible with managed permission profiles. It does not provide a reliable replacement for the
bwrappath.Why this matters
The desired security model is:
workspace-writedanger-full-accessseccomp=unconfined/apparmor=unconfinedapply_patchto update files inside the workspaceCurrently there is no reliable mode that satisfies this.
This is especially problematic because the failure pushes the agent toward less desirable workarounds: asking for broad shell access, editing files through scripts, or requiring users to weaken container security. That is exactly what
apply_patchshould avoid.Architectural concern
This looks like an architectural issue, not just a missing package or local Docker misconfiguration.
Ordinary workspace-confined file edits should not depend on a
bwrapnamespace setup that commonly fails in devcontainers. Other agentic coding tools used in the same development environment do not hit this failure mode, including Claude Code, GitHub Copilot coding agents and Cursor CLI. They still preserve their own approval/permission models, but they do not make normal workspace file edits fail becausebwrapcannot create namespaces.Codex should not require users to choose between:
danger-full-access,just to perform normal approved workspace patches.
Expected behavior
Codex should provide a safe patch path that does not fail when
bwrapcannot create namespaces inside a devcontainer.Possible acceptable fixes:
apply_patchfrom thebwrapruntime sandbox and enforce workspace boundaries through the Codex permission model.bwrapnamespace failures and use a compatible fallback that still preserves approvals and workspace boundaries.Related issues that seem connected:
Additional confirmed workaround on Ubuntu 24.04: AppArmor
usernsprofile for Codex itself.I could reproduce the failure with
kernel.apparmor_restrict_unprivileged_userns=1from an unprofiled terminal:Temporarily disabling the Ubuntu AppArmor userns restriction made both probes pass:
I did not want to leave that sysctl disabled globally.
The useful clue was that official VS Code from the
.debpackage worked because Ubuntu ships an AppArmor profile like this:For Homebrew-installed Codex on an x86_64 host, this AppArmor profile fixed
apply_patchadd/update/delete without relaxing the whole system:Install/load:
After restarting Codex:
Then
apply_patchcould update an existing file again.One narrower profile attempt did not work:
That attached to the Codex process, but Codex still failed with namespace setup errors, which suggests user namespace creation happens before that transition or through a helper path other than direct
/usr/bin/bwrap.So the practical workaround is: keep
kernel.apparmor_restrict_unprivileged_userns=1, but add a Codex-specific AppArmor compatibility profile withuserns,.This is narrower than disabling the sysctl globally or profiling the whole terminal, but broader than granting
usernsonly to bwrap.hey @dpritchett, does the workaround for Ubuntu 24.04 mention on https://developers.openai.com/codex/concepts/sandboxing#prerequisites work for you?
@viyatb-oai, yep!
I tested the documented Ubuntu 24.04 workaround.
Steps:
After fully restarting Codex, the Codex process was no longer under my Codex-specific profile:
Both
bwrapprobes then passed:I also verified that
apply_patchcan update an existing workspace file. So yes, the documentedbwrap-userns-restrictworkaround resolves my local failure too while keepingkernel.apparmor_restrict_unprivileged_userns=1.Thanks for pointing me at the documented path. For completeness, the Codex-specific profile I posted earlier also works, but the distro-provided
bwrap-userns-restrictprofile is clearly easier to recommend/support for Ubuntu 24.04 users.Additional reproduction on Codex CLI 0.144.3.
Environment:
Observed during a small LICENSE / pyproject / todo.md edit:
~~~text
apply_patch verification failed: Failed to read file to update .../pyproject.toml: fs sandbox helper failed with status exit status: 1: bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted
~~~
Expected behavior:
This is not a container-only case from the user perspective; the repo is a normal Linux workspace with group-writable files.
Adding another variant of what looks like the same failure class (bwrap sandbox setup failing in restricted environments before the requested command runs).
Environment
kernel.apparmor_restrict_unprivileged_userns = 0globally,kernel.unprivileged_userns_clone = 1— i.e. the global sysctls are permissive; the restriction comes from the per-service hardeningObserved
Sandboxed exec fails during bwrap setup with an error referencing
/proc/sys/kernel/overflowuid(bwrap cannot read it during uid-map/userns setup), so--sandbox read-onlyand--sandbox workspace-writeare both unusable for that user.Workaround
--sandbox danger-full-accessfor review-style (read-only-by-convention) tasks. Works, but it means the sandbox is opt-out exactly in the hardened environments where you'd most want it enforced.Suggestion
Same as the OP's expected-behavior note: a supported fallback (e.g. landlock/seccomp-only mode, or a preflight that detects userns/bwrap unavailability and degrades with a clear message) would help. Happy to run diagnostics if useful.
Another confirmed reproduction on Codex CLI
0.144.5, with a slightly different initial condition: the distrobubblewrappackage was not installed, so Codex used its bundled helper.Environment
6.17.0-1013-aws0.144.5command -v bwrap: no result before the fixkernel.unprivileged_userns_clone = 1user.max_user_namespaces = 125266kernel.apparmor_restrict_unprivileged_userns = 1Observed behavior
Every sandboxed command, including
pwd, failed before execution with:Because shell calls could retry with escalation, even routine read-only commands were routed through Auto-review. Each command then produced the review rationale, approval event, and unsandboxed execution event. This made ordinary coding turns very noisy and shifted routine commands outside the intended sandbox boundary.
I did not see a one-time actionable startup diagnostic identifying the missing distro package/AppArmor profile.
Verified fix
After loading the profile, the existing Codex session immediately ran
pwdandgit status --shortinside the sandbox without Auto-review escalation. AppArmor remained enabled andkernel.apparmor_restrict_unprivileged_usernsremained1.Suggested improvement
Please preflight the complete Bubblewrap path, including loopback initialization—not only helper presence or basic user-namespace creation. When this fingerprint is detected, Codex could surface one actionable Ubuntu-specific diagnostic instead of repeatedly escalating each command. A
codex doctorcheck for the distrobwrappackage and the loadedbwrap-userns-restrictprofile would also make this much easier to diagnose.