codex - 💡(How to fix) Fix Better diagnostic when Linux sandbox fails due to AppArmor unprivileged userns restriction [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#19285Fetched 2026-04-24 10:39:20
View on GitHub
Comments
2
Participants
2
Timeline
8
Reactions
0
Timeline (top)
labeled ×4commented ×2closed ×1cross-referenced ×1

Error Message

The current error surfaced to the user was too low-level to be actionable: Sandboxed commands fail with a low-level error: When the Linux sandbox backend cannot initialize because unprivileged user namespaces are blocked by host policy, Codex should emit a higher-level diagnostic instead of only the low-level sandbox error. This issue is difficult to diagnose from the current error output. It can easily appear as:

Root Cause

Codex CLI on Ubuntu failed to run even trivial sandboxed commands because the Linux sandbox backend could not create its namespace setup under AppArmor’s unprivileged user namespace restriction.

Code Example

bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted

---

bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted

---

unshare -Ur true
# unshare: write failed /proc/self/uid_map: Operation not permitted

---

sysctl kernel.unprivileged_userns_clone
# 1

---

sysctl user.max_user_namespaces
# high/nonzero

---

sysctl kernel.apparmor_restrict_unprivileged_userns
# 1

---

sysctl kernel.apparmor_restrict_unprivileged_userns
   # 1

---

kernel.apparmor_restrict_unprivileged_userns = 1

---

sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

0.123.0

What subscription do you have?

Pro

Which model were you using?

gpt-5.4-codex

What platform is your computer?

Linux 6.8.0-107-generic x86_64 x86_64

What terminal emulator and version are you using (if applicable)?

N/A

What issue are you seeing?

Codex CLI on Ubuntu failed to run even trivial sandboxed commands because the Linux sandbox backend could not create its namespace setup under AppArmor’s unprivileged user namespace restriction.

The current error surfaced to the user was too low-level to be actionable:

bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted

In practice, this made Codex look broken or misconfigured, when the actual problem was host policy.

Sandboxed commands fail with a low-level error:

bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted

A direct namespace test also failed:

unshare -Ur true
# unshare: write failed /proc/self/uid_map: Operation not permitted

System state:

sysctl kernel.unprivileged_userns_clone
# 1
sysctl user.max_user_namespaces
# high/nonzero
sysctl kernel.apparmor_restrict_unprivileged_userns
# 1

What steps can reproduce the bug?

  1. Run Codex CLI on Ubuntu Linux (kernel 6.8.0-107-generic) with AppArmor enabled.
  2. Ensure:
    sysctl kernel.apparmor_restrict_unprivileged_userns
    # 1
  3. Start a Codex TUI session.
  4. Run a trivial sandboxed command (e.g., pwd).
  5. Observe failure before execution.

Additional notes:

  • Reproducible in normal sandboxed execution.
  • Running outside the sandbox still works.
  • Rolling back Codex from 0.124.0 to 0.123.0 does not fix it.

What is the expected behavior?

When the Linux sandbox backend cannot initialize because unprivileged user namespaces are blocked by host policy, Codex should emit a higher-level diagnostic instead of only the low-level sandbox error.

Example guidance:

  • Sandbox initialization failed
  • Unprivileged user namespaces may be blocked by AppArmor or host policy
  • Check kernel.apparmor_restrict_unprivileged_userns
  • Try a diagnostic like: unshare -Ur true

Additional information

Environment:

  • OS: Ubuntu Linux
  • Kernel: 6.8.0-107-generic
  • Codex CLI versions tested:
    • 0.124.0
    • 0.123.0 (rollback did not resolve issue)
  • Install method: npm global install
  • Shell/session type: terminal TUI session

Why this matters:

This issue is difficult to diagnose from the current error output. It can easily appear as:

  • A Codex regression
  • A bad update
  • A broken sandbox mode
  • Incorrect approval behavior

In this case, the issue initially appeared to be caused by an update, but was actually due to an AppArmor restriction on the host system.

Suggested improvement:

On Linux, if sandbox startup fails in this class of failure, Codex could:

  1. Detect the userns / uid_map failure path
  2. Check whether kernel.apparmor_restrict_unprivileged_userns = 1
  3. Surface a targeted explanation
  4. Clearly distinguish “sandbox backend unavailable” from ordinary approval escalation

Repro note:

Observed on Ubuntu with AppArmor enabled and:

kernel.apparmor_restrict_unprivileged_userns = 1

After setting:

sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0

and restarting Codex, sandboxed execution worked normally again.

extent analysis

TL;DR

The issue can be resolved by setting kernel.apparmor_restrict_unprivileged_userns to 0, allowing unprivileged user namespaces.

Guidance

  • Check the current value of kernel.apparmor_restrict_unprivileged_userns using sysctl kernel.apparmor_restrict_unprivileged_userns.
  • If the value is 1, try setting it to 0 using sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 to allow unprivileged user namespaces.
  • Verify that sandboxed execution works after making this change by running a trivial sandboxed command.
  • Consider implementing a diagnostic in Codex to detect and surface a targeted explanation when sandbox startup fails due to AppArmor restrictions.

Example

To set the value of kernel.apparmor_restrict_unprivileged_userns to 0, run the following command:

sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0

Then, restart Codex and try running a sandboxed command again.

Notes

This solution assumes that the issue is caused by the AppArmor restriction on unprivileged user namespaces. If the issue persists after making this change, further debugging may be necessary.

Recommendation

Apply the workaround by setting kernel.apparmor_restrict_unprivileged_userns to 0, as this allows unprivileged user namespaces and resolves the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Better diagnostic when Linux sandbox fails due to AppArmor unprivileged userns restriction [2 comments, 2 participants]