Linux sandbox fails on Ubuntu with AppArmor userns restrictions: bwrap loopback RTM_NEWADDR EPERM
Summary
On Ubuntu, native npm-installed Codex fails to use its Linux sandbox when AppArmor unprivileged user namespace restrictions are enabled.
Repro
codex sandbox linux /bin/true
Actual result
bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted
Expected result
codex sandbox linux /bin/true should exit successfully.
Environment
- Codex:
codex-cli 0.115.0 - Install method: native npm install
- OS: Ubuntu
- bubblewrap:
0.11.0-2 - apparmor:
5.0.0~alpha1-0ubuntu8.3
Relevant sysctls:
kernel.apparmor_restrict_unprivileged_userns = 1
kernel.apparmor_restrict_unprivileged_unconfined = 1
Diagnosis
The issue appears to be in the native Linux sandbox path, not the JS/npm wrapper.
Tracing showed the sandbox fails when trying to assign 127.0.0.1/8 to loopback inside the sandboxed network namespace. The RTM_NEWADDR request returns EPERM.
Confirmed workaround
I confirmed a targeted AppArmor profile fixes the issue without disabling the restriction globally.
Profile used:
abi <abi/4.0>,
include <tunables/global>
@{codex_bin} = /home/nitro/.local/share/fnm/node-versions/v24.12.0/installation/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex/codex
profile codex-native @{codex_bin} flags=(unconfined) {
userns,
@{codex_bin} mr,
include if exists <local/codex-native>
}
Then:
sudo install -m 0644 /tmp/codex-native.apparmor /etc/apparmor.d/codex-native
sudo apparmor_parser -r /etc/apparmor.d/codex-native
sudo mv /etc/sysctl.d/60-codex-userns.conf /etc/sysctl.d/60-codex-userns.conf.disabled
sudo sysctl --system
codex sandbox linux /bin/true
After this:
kernel.apparmor_restrict_unprivileged_userns = 1kernel.apparmor_restrict_unprivileged_unconfined = 1codex sandbox linux /bin/truesucceeds
This keeps Ubuntu's AppArmor restrictions enabled globally and grants a targeted exception only to the native Codex binary.
Request
Please either document the Ubuntu/AppArmor requirement, detect this case with a better error, or provide guidance for a targeted AppArmor profile workaround.
12 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
I can confirm this is still affecting a real Ubuntu Azure VM setup with newer Codex.
Environment:
0.116.0bubblewrap:/usr/bin/bwrap, version0.9.0bubblewrapinstalled from apt6.8.0-1031-azureObserved behavior:
bubblewrapbwrap: loopback: Failed RTM_NEWADDR: Operation not permittedImportant host state:
kernel.apparmor_restrict_unprivileged_userns = 11, Codex sandboxing failed againsudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0What this suggests:
codex-cli 0.116.0and system/usr/bin/bwrapinstalled, Ubuntu/AppArmor userns restriction still breaks Codex sandboxing on this host after reboot unless the sysctl is temporarily relaxedmissing /usr/bin/bwrapproblemIt would help if Codex could either:
The root cause is that bwrap depends on unprivileged user namespaces for network namespace setup (loopback configuration), and Ubuntu's AppArmor policy blocks this by default (
apparmor_restrict_unprivileged_userns = 1). The workarounds -- custom AppArmor profiles, disabling the sysctl -- weaken the host security posture to accommodate the sandbox, which is counterproductive.An alternative approach is to not use namespaces at all. sandlock provides process sandboxing using Landlock + seccomp-bpf + seccomp user notification -- no user namespaces, no mount namespaces, no network namespaces. Nothing that AppArmor restricts.
Network isolation is handled via Landlock TCP port rules (kernel 6.7+) and seccomp notification for domain-based allowlisting, rather than creating a network namespace and configuring loopback.
Disclaimer: I'm the sandlock author.
Saying that using the AppArmor profiles to allow _specific_ applications that use user namespaces for increased sandboxing to work, is a _less_ secure solution than using an untested vibecoded isolation tool is...quite the claim.
I can confirm this is still reproducible for me on Ubuntu 24 with Codex 0.117.0.
Environment:
codex-cli 0.117.00.9.0So in my case this still fails on 0.117.0, even though the 0.117 release notes mention improved Linux sandbox reliability.
I also see a related user-facing symptom in normal Codex runs: for each attempted file edit I get the approval prompt:
without showing me the file list.
To clarify -- sandlock uses Landlock LSM and seccomp-bpf, both of which operate within the existing namespace. No user namespaces, no network namespaces, no
RTM_NEWADDR. That's why it isn't affected byapparmor_restrict_unprivileged_usernsat all.This isn't a workaround for the AppArmor restriction -- it's a different architecture that doesn't need namespaces in the first place. Landlock and seccomp are upstream kernel security primitives, not something sandlock invented.
Regarding testing: the project has 131 Rust integration tests and 63 Python tests covering syscall filtering, network isolation, resource limits, filesystem COW, and policy enforcement. Happy to have more eyes on it.
Looks similar to https://github.com/openai/codex/issues/14936
Still reproducible on my machine as of 2026-04-20.
Environment:
Repro:
Actual:
Additional check outside Codex sandbox:
returns:
This is not workspace-specific; I see the same failure in /tmp and in a trusted project directory.
Confirmed workaround here too:
succeeds and prints the working directory.
So this still affects the current CLI and the Landlock fallback still works.
@g-i-o-r-g-i-o how was bubblewrap installed - via
aptand is this a docker container?Paste the output of
please follow the instructions on https://developers.openai.com/codex/concepts/sandboxing#prerequisites for ubuntu 24.04 and let me know if you can still reproduce this on latest codex release.
<img width="1870" height="1028" alt="Image" src="https://github.com/user-attachments/assets/698a275a-731c-4f64-9397-e64cd1808b90" />
I have no root rights on the development machine. I cannot run the provided instructions.
In my case executing
codex sandbox linux /bin/pwdworks, but during a coding session I keep on getting plenty of requests to allow codex to perform all commands due to failure to execute in the sandbox.