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.
18 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.I wanted to report back after testing the documented Ubuntu 24.04 solution.
I originally reproduced this issue (see #17337). At that time I was only able to get
workspace-writeworking by enabling the legacy Landlock fallback.I have now tested the documented
bwrap-userns-restrictAppArmor profile on Ubuntu 24.04.4 LTS with Codex CLI 0.144.2.Results:
kernel.apparmor_restrict_unprivileged_userns = 1remains enabled.unshare -Urn truestill fails for an ordinary user, as expected.codex execworks normally inworkspace-write.So, at least on my system, the documented Ubuntu 24.04 procedure resolves the issue without disabling the global AppArmor restriction.
One small suggestion: when Codex encounters
bwrap: loopback: Failed RTM_NEWADDR: Operation not permittedit might be helpful if the error message pointed users directly to the Ubuntu 24.04 AppArmor instructions, since that appears to be the supported solution.
I can reproduce the same failure family in a VS Code Dev Container running under Docker on WSL2.
Environment
openai.chatgpt@26.727.408160.145.0and0.146.0Inside the Dev Container:
The same user-namespace test succeeds on the WSL2 host, so this appears to be a nested Docker/Dev Container namespace restriction rather than only the Ubuntu 24.04 host AppArmor case described in the documented workaround.
Minimal comparison test
I created the following disposable file in the workspace:
Its initial contents were:
I then requested the same operation through both launch paths:
VS Code extension result
The VS Code extension failed before it could read or update the existing file:
After the failure, the file contents remained:
The file was normally readable and writable from the Dev Container terminal.
Codex CLI result
In the same container, with the same user, workspace and test file, I started Codex CLI explicitly with:
I requested the same
apply_patchoperation.This time the operation succeeded, and the file contents changed to:
I reproduced this result with Codex CLI
0.145.0and again after upgrading to0.146.0.Configuration observation
A Codex CLI session started without explicit flags also reads the following top-level
config.tomlsettings correctly:Its
/statusoutput reports:However, the VS Code extension’s
apply_patchfilesystem helper still attempts to use the failingbwrappath.Comparison
| Launch path | Requested change | Result | Final file contents |
| -------------------------------------------- | -------------------------------------- | ------------------------------------------- | ------------------- |
| VS Code extension |
before→afterusingapply_patch| Fails through thebwrapfilesystem helper |before|| CLI with explicit
danger-full-accessflags |before→afterusingapply_patch| Succeeds |after|Current workaround
For development work, I am using an explicit wrapper around:
I did not weaken the Dev Container with any of the following:
I also removed the host Docker socket mount before using
danger-full-access.Possible improvement
It would be helpful if Codex could:
bwrapcannot create the required namespaces inside a Dev Container;apply_patchthat preserves approvals and workspace boundaries;The main additional datapoint is that the same disposable file update fails through the VS Code extension but succeeds through explicitly launched Codex CLI. The extension-side failure remained after the installed Codex CLI was upgraded from
0.145.0to0.146.0, while the explicitly launched CLI succeeded with both versions.Additional workaround for Codex's bundled Bubblewrap
I hit the same
bwrap: loopback: Failed RTM_NEWADDR: Operation not permittedfailure on Ubuntu 24.04.4, but in my case enabling Ubuntu's standardbwrap-userns-restrictprofile alone did not resolve it.The important difference was that Codex was not using
/usr/bin/bwrap. It was using its bundled helper:Because Ubuntu's standard AppArmor profile matches
/usr/bin/bwrap, the bundled Codex helper continued to fall through to the genericunprivileged_usernsprofile and was deniedsetpcapandnet_admin.I created an AppArmor profile based on Ubuntu's supplied
bwrap-userns-restrictprofile, but matched it against:After loading that profile, the bundled Codex
bwrapsucceeded.I then verified
apply_patchby:Both operations completed using the normal patch helper, with no shell/perl/python fallback and no namespace error.
So for installations where Codex continues to use its bundled
bwrap, extending the distro AppArmor approach to the bundled helper path appears to be another working option while keeping:Environment:
Happy to post the exact AppArmor profile if useful.
Update: I upgraded the standalone Codex install to
0.147.0, fully restarted the remote Codex processes, and re-testedapply_patch.Result:
The targeted AppArmor workaround for Codex's bundled
bwraptherefore still works on0.147.0in this environment, while keeping:enabled globally.
Confirmed recurrence on the current standalone release with a more specific AppArmor diagnosis.
Environment
6.17.0-1022-gcpcodex-cli 0.147.0bubblewrappackage installed; Codex uses its own bundledcodex-resources/bwrapkernel.unprivileged_userns_clone = 1kernel.apparmor_restrict_unprivileged_userns = 1unprivileged_usernsprofile enforcingReproduction
A read-only command such as
pwdcan succeed, but a command requiring the normalworkspace-writesandbox fails before the requested command executes:apply_patchfails at sandbox initialization as well:A controlled test confirmed the target file was never read or modified. A normal shell write outside the failing managed sandbox succeeds, so this is not a repository/filesystem permission problem.
AppArmor evidence
Kernel audit entries emitted at the exact reproduction times show the bundled Codex
bwraptransitioning fromunconfinedto theunprivileged_usernsprofile and then receiving capability denials including:The
execpathin the audit log points to the Codex-bundledcodex-resources/bwrap.This matches the failure point:
bwrapcreates the sandbox namespace and then cannot configure the loopback address becauseCAP_NET_ADMINis denied, producing theRTM_NEWADDRerror.Namespace checks
unshare -U truesucceedsSeccomp: 0in the relevant Codex process context)Update status
The standalone CLI's supported updater is
codex update(notcodex --upgradein this build). Running the official updater on 2026-08-11 resolved the latest available version as0.147.0; the issue remains reproducible afterward.Security consideration
I have intentionally not disabled AppArmor, set
kernel.apparmor_restrict_unprivileged_userns=0, granted capabilities to the bundledbwrap, made it setuid, or run Codex as root. A fix/fallback in Codex would be preferable to requiring a host-wide weakening of Ubuntu's security policy.This appears to be the same root issue reported here, still present in standalone
0.147.0.Confirmed on the current standalone release (
codex-cli 0.149.1).Environment:
6.8.0-138-generic0.149.1(x86_64-unknown-linux-musl)0.9.0codex-resources/bwrapkernel.unprivileged_userns_clone = 1kernel.apparmor_restrict_unprivileged_userns = 1user.max_user_namespaces = 62106apparmor-profilesandapparmor-utilsare not installed, so/usr/share/apparmor/extra-profiles/bwrap-userns-restrictand/etc/apparmor.d/bwrap-userns-restrictare absentObserved behavior:
bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted, then require an escalated retry;apply_patchcannot read an existing target file through the filesystem sandbox and falls back to a nonstandard edit path;Minimal host probes:
This also causes the excessive per-command approval behavior described in #34207.
I have not disabled AppArmor or changed the global sysctl. Next I plan to test the documented Ubuntu 24.04
bwrap-userns-restrictworkaround. Since this is a standalone Codex install with a bundled helper, it would still be useful for Codex to detect this fingerprint at startup and point directly to the supported remediation (and account for the bundledcodex-resources/bwrappath), instead of repeatedly escalating each command.Follow-up: the Ubuntu AppArmor remediation resolved the failure on my machine without disabling the global restriction.
What I did:
Post-fix validation:
The Codex CLI sandbox test now passes, and
codex doctor --summaryreports:A minimal workspace read through the Codex sandbox also exits successfully. I did not change
kernel.apparmor_restrict_unprivileged_userns(it remains1).Important implementation detail: an
execvetrace shows Codex CLI 0.149.1 uses/usr/bin/bwrapfor the active sandbox path. The Codex-bundledcodex-resources/bwrapstill fails when invoked directly because the Ubuntu profile matches/usr/bin/bwrap; however, this does not affect the current CLI path.Persistence: the profile is installed under
/etc/apparmor.d/and the AppArmor service is enabled, so this should survive reboot. It may need reloading after profile/package changes. A startup preflight could detect the knownRTM_NEWADDRfingerprint and point users to this supported Ubuntu remediation instead of repeatedly escalating commands.Additional reproduction: apply_patch blocked at user-namespace initialization
I’m seeing the same apply_patch sandbox failure family in a Codex execution environment.
Observed error
apply_patch verification failed: fs sandbox helper failed with status exit status: 1
bwrap: No permissions to create new namespace, likely because the kernel does not allow non-privileged user namespaces.
The failure occurs before target-file access.
Independent control
unshare --user --map-root-user true
fails with:
Operation not permitted / exit 1.
Relevant diagnostics
/proc/sys/user/max_user_namespaces = 31103
UID/GID maps cover the full 32-bit range
NoNewPrivs=0
Seccomp=2 with two filters
no effective/permitted capabilities
workspace filesystem is writable
ordinary shell write/read/remove succeeds
no target-path permission error
a fresh Codex execution reproduced the same failure
Conclusion supported by the observations
The current Codex execution boundary denies creation of the unprivileged user namespace required by the bwrap-backed patch sandbox. The exact seccomp/LSM/container-runtime rule causing the denial is not observable from inside the current runtime.
This makes apply_patch unusable even though the workspace itself is writable.
I recently moved the workflow to a ChatGPT Business workspace, but I do not have evidence that the account change is causal.
A supported patch path that works when nested/unprivileged user namespaces are unavailable would avoid requiring host-wide security changes.