Linux sandbox: absent protected .codex plus explicit deny produces conflicting directory/file masks and prevents command startup
SUMMARY
Observed on the official Codex CLI 0.162.0 Linux x86_64 binary, Ubuntu 24.04 on WSL2, Python 3.12.3 and bubblewrap 0.9.0-1ubuntu0.3. A managed restricted profile grants a synthetic workspace write access and explicitly denies its .codex child. When workspace/.codex is absent before command startup, the native sandbox command exits 1 with:
bwrap: Can't create file at <synthetic-workspace>/.codex: Is a directory
The command payload does not execute. This is a startup compatibility defect; we have not demonstrated an information disclosure, privilege escalation or sandbox escape. All work used synthetic files and offline controls, not secrets.
OBSERVED REPRODUCTION SHAPE
- An outer, unprivileged bubblewrap world supplies only synthetic workspace, configuration and runtime fixtures. Its Linux system requirements are bind- supplied inside that world; the installed host policy is not replaced.
- A managed permissions profile denies the filesystem root, grants minimal runtime reads and workspace writes, protects metadata, explicitly denies workspace/.codex, and disables network access.
- workspace/.codex is deliberately absent, not a symlink. It is kept absent in all three failing cases. The unrelated /run/current-system fixture varies among absent, directory and symlink-to-directory layouts.
- Native invocation uses codex sandbox with an explicit permission profile, --include-managed-config and --cd pointing at the synthetic workspace.
- Each absent-.codex case exits 1 with the file/directory mask error above.
The existing full harness produced these failures; this draft does not attach the private harness or claim that a newly minimized standalone reproducer was executed. Paths and account names are deliberately omitted. Reproduction should use a separate disposable namespace and must not overwrite system policy.
CONTROLS AND LIMITATIONS
The earlier harness also had a separate TMPDIR precedence error in cases where .codex existed. That error was corrected in a later harness by using /tmp for TMPDIR while retaining a distinct explicit writable test-temp directory. Do not conflate that PermissionError with the absent-.codex mount collision.
The corrected harness subsequently ran eleven present-.codex cases: six complete restricted executions and five recognized managed-policy rejections, with positive controls before/after. The three absent cases were NOT rerun in that subset. Their current evidence is historical native failure plus source review. No claim is made that all fourteen cases pass, that all WSL routes are isolated, or that a desktop agent uses this exact standalone binary.
SOURCE HYPOTHESIS, NOT A TESTED PATCH
In bwrap.rs at rust-v0.162.0 / rust-v0.162.1:
- Lines 699-743 restore protected metadata paths into read-only subpaths and emit their masks before the nested unreadable-root phase at lines 763-774.
- Lines 1286-1292 handle missing protected metadata as an empty directory.
- Lines 1353-1358 separately handle a missing denied path inside a writable root as an empty file. Host-side existence still reports the path absent.
Inference: the emitted plan first creates a directory mount target, then attempts a file-style mask on that same destination. Reconcile overlapping mask phases and their planned target types without relaxing either metadata or deny rules.
https://github.com/openai/codex/blob/rust-v0.162.0/codex-rs/linux-sandbox/src/bwrap.rs#L699 https://github.com/openai/codex/blob/rust-v0.162.1/codex-rs/linux-sandbox/src/bwrap.rs#L1286
The complete file is identical between these two release tags (Git blob f4a428b20b1bfc3efbd14cedc3de08915e873d8a). The main snapshot inspected on 2026-10-12, blob 51200dc4bda38f84b5f14c1a92aa4087ce8cf346, still contains this phase ordering and these helpers at shifted line numbers. No native test of 0.162.1 or main was performed. A source comparison is not runtime certification.
REGRESSION ACCEPTANCE REQUEST
- Preserve a genuinely absent metadata fixture and leave host contents unchanged.
- Start and execute the command successfully under the restricted policy.
- Verify denied metadata cannot be read, listed or created; retained workspace writes/atomic replace and all positive controls must still succeed.
- Cover existing directories, missing paths, writable/immutable symlink routes, nested write roots and contradictory overrides without weakening fail-closed treatment where enforcement is genuinely impossible.
- Retain denied network, runtime sockets and alias/proc protections in the surrounding acceptance matrix. Test the Linux implementation, not only a modeled argument list or a build on another OS.
Do not solve this by removing the deny, granting full access, precreating the missing fixture, changing its expected outcome to passed, or silently substituting another sandbox. This report does not request any of those changes.
RELATED BUT NOT ESTABLISHED AS DUPLICATES
https://github.com/openai/codex/issues/52658 This concerns two file-deny spellings through a symlink and an ENOENT failure. Our observed missing-metadata directory/file collision does not require duplicate aliases; that report is not evidence of a fix for this case.
Release checked: https://github.com/openai/codex/releases/tag/rust-v0.162.1 Latest stable returned by the release API during this review. Its notes do not establish a correction of this case. No upgrade or custom build was performed.
Confirmed the root cause by source review on current main (97239fd). It's a re-add after the deny filter, not just phase ordering:
- bwrap.rs#L690 drops paths that are in
unreadable_pathsfromread_only_subpaths, so an explicit deny onworkspace/.codexis filtered out here. - bwrap.rs#L712 then calls
append_metadata_path_masks_for_writable_root, which re-addsroot.join(".codex")unconditionally (L854-L865). - Because
.codexis missing,append_missing_read_only_subpath_argsmasks it as an empty directory (--tmpfs+--remount-ro, L1336-L1343). - The same path is still an unreadable root, so
append_unreadable_root_argstakes the!exists()branch and emits a file mask (--ro-bind-data) viaappend_missing_empty_file_bind_data_args(L1403-L1409). bwrap then fails withCan't create file at …/.codex: Is a directory.
When .codex exists, both masks resolve to the existing directory type, which is why only the absent case fails.
Suggested direction: when a protected metadata path is also an unreadable root, let the deny mask own it (it is strictly stronger) and skip adding it in append_metadata_path_masks_for_writable_root. Care is needed at L845: once the path is no longer in read_only_subpaths, append_protected_create_targets_for_writable_root would register a ProtectedCreateTarget for it, overlapping the deny file mask. Symlinked roots also need the same check after remap_paths_for_symlink_target.
I haven't run this under bwrap; a regression test covering absent metadata + explicit deny (and the symlinked-root variant) would pin it down.
Source-only follow-up to the review at 97239fd: the proposed fix needs both the metadata-mask exclusion and the ProtectedCreateTarget exclusion, comparing the effective destinations after symlink remapping.
There is also a separate detail for strict no-read acceptance. The missing-deny branch emits --ro-bind-data without --perms. Upstream bubblewrap v0.9.0 defaults this operation to mode 0600. Source review therefore suggests that the empty placeholder may remain readable by its owner after the startup collision is removed. This is not evidence of disclosure of host contents or a native reproduction of that behavior.
A local, uncompiled candidate now:
- filters the overlapping read-only metadata masks after both path lists are remapped;
- excludes the same effective deny destinations from
ProtectedCreateTarget; - emits
--perms 000immediately before a missing-deny file mask, retaining ordinary read-only missing-path behavior; - retains the writable-symlink deny rejection.
The drafted native regression covers absent/existing .codex with ordinary/symlinked roots, including a direct : < .codex read-open attempt, blocked metadata writes/listing, allowed workspace atomic replacement, and host-fixture preservation. An absent fixture must return NotFound before/after; unavailable native prerequisites must not count as a passing regression.
Only source review and patch-text reapplication checks have been performed. No compilation, native bwrap run, installation or policy modification was performed. Maintainer review and Linux execution are still needed before calling either the startup fix or strict deny behavior validated.
Additional reproduction on official Linux releases 0.169.0 and 0.172.0, using the public TradingCodex v2.1.3 generated trading-research permission profile. This appears consistent with the missing protected-metadata mask collision described above.
Environment and observed results
- Disposable Ubuntu 22.04 x86-64 CI runners; fresh workspace generated by
tcx attachfrom public TradingCodex commit721f3c1e. - Verified full official Linux musl packages for 0.169.0 and 0.172.0, including their respective bundled bwrap helpers. System bwrap was excluded from the test PATH.
- In the disposable workspace, removed the deprecated
multi_agent = trueline while retaining explicit V2 configuration, and supplied[features] unified_exec = falsethrough a private mount namespace's managed requirements file. No installed host policy was changed. The original TradingCodex CLI contract then passed strict config, feature checks, and trust for its five hooks. The filesystem deny rules were unchanged. - On both releases the built-in
:read-onlycontrol executed a harmlessprintfand independently refused a write. The generatedtrading-researchprofile failed before the shell command or native turn could execute, withbwrap: .../workspace/.aws: Is a directory. - In a separate fixture sensitivity test, creating empty
.aws,.sshand.gnupgdirectories moved the failure totrading/approvals. Creating the named protected trading directories moved it to a read-only filesystem failure while constructing the protected database path. This did not establish a successful workaround.
Reproduction entrypoints Public generated profile: https://github.com/monarchjuno/tradingcodex/blob/721f3c1e9dab2c8a4280ce094cca33d506dcfe33/workspace_templates/modules/codex-base/files/.codex/config.toml
In an isolated, credential-free environment, generate a fresh workspace with the public application and test codex sandbox -C <workspace> -P trading-research --include-managed-config -- /bin/sh -c 'printf SANDBOX_OK', with project trust and managed requirements confined to the disposable test environment. Compare against an independent built-in read-only control. The full generated profile contains both explicit protected metadata denies and nested protected trading/state paths; this is not a claim that this comment alone is a fully self-contained reproduction script.
Source hypothesis / request
The observed behavior is consistent with separate directory/file mask selection for the same absent protected path in bwrap.rs. See 0.172.0 mask selection. Please consider a regression test covering a genuinely absent .aws (or .codex) with explicit deny under a writable root, plus nested denies below protected parents. Expected: allowed commands and workspace writes succeed, denied reads/writes/listing/creation remain denied, host contents stay unchanged, and no credential or network protections are weakened. Related: #40433.
This is a startup compatibility defect, not a demonstrated sandbox escape. No secrets, live accounts, model inference or production state were used in these probes. We would prefer a fix in the official distribution rather than maintaining a custom fork. Is there a supported permission-profile migration that preserves these protections, or an upcoming release containing the planner correction?