Skip to content

codex exec fails in an outer read-only sandbox because installation_id requires write access #42398

Open
argszero/codex
#1

Description

@TyceHerrman

What version of Codex CLI is running?

codex-cli 0.151.0

The rust-v0.152.0 source has an identical installation_id.rs and still calls its resolver during in-process app-server startup. 0.152.0 was inspected, not installed or run.

What subscription do you have?

Pro

Which model were you using?

No model turn was reached; the CLI failed during startup.

What platform is your computer?

macOS 27.0, Apple Silicon (arm64).

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

The CLI was launched as a subprocess from a Codex Desktop task.

Codex doctor report

Not collected. Startup logs and a focused filesystem probe are described below.

What issue are you seeing?

A nested codex exec fails before emitting any JSON events when the enclosing task sandbox allows reading ~/.codex/installation_id but denies writing it:

Error: failed to initialize in-process app-server client: Operation not permitted (os error 1)

Two launches exited with code 1 and empty stdout, requesting inner read-only and workspace-write sandboxes respectively. Both inherited the same outer restrictions. Redirecting logs and SQLite to writable fixture directories, disabling analytics, and using --ephemeral did not avoid the failure.

This blocks starting a read-only worker with existing Codex state. The diagnostic does not identify which file requires write access.

What steps can reproduce the bug?

  1. On macOS, launch a child CLI from an enclosing Codex task that denies writes to ~/.codex/installation_id while allowing reads. The observed file already existed, was user-owned, and had mode 0644.

  2. Provide a synthetic Git repository and writable directories for logs, SQLite, temporary files, and caches. Retain the existing Codex home.

  3. Launch codex exec with these relevant arguments:

    codex -a never exec --sandbox read-only --ephemeral --json \
      -C /path/to/synthetic-repo \
      -c 'log_dir="/path/to/writable-logs"' \
      -c 'sqlite_home="/path/to/writable-sqlite"' \
      -c 'analytics.enabled=false' \
      -c 'history.persistence="none"' \
      "Read sample.py."

    This is a shortened representation of the recorded invocation, not an independently tested minimal reproducer. The actual launches also configured a fixture MCP server, disabled unrelated plugins/hooks, and used longer validation prompts. The fixture MCP connection was never reached.

  4. Observe the startup error above. Setting the inner CLI's --sandbox read-only alone does not create the required outer restriction; that flag controls the worker's tool execution.

A separate probe in the same enclosing sandbox confirmed:

Operation on the existing installation-ID file Result
os.open(path, os.O_RDONLY) Succeeds
os.open(path, os.O_RDWR) Fails with EPERM / errno 1
File contents before and after the probe Unchanged

What is the expected behavior?

Reusing a valid existing installation ID should not require opening the file for writing. If startup requires a write, its error should name the path and operation that failed.

Additional information

In 0.151.0's resolver, the file is opened with:

options.read(true).write(true).create(true);

This happens before reading and validating the existing UUID. 0.152.0 retains that implementation, and app-server startup propagates its error.

The denied writable open and this call path identify a startup blocker. A patched binary has not been tested, so this report does not establish that removing this blocker is sufficient for the entire nested session to run.

Consider reading and reusing a valid ID without a writable open, retaining the locked write path for creation or repair. Regression coverage should include an existing valid ID with writes denied, missing/invalid IDs in a writable home, and concurrent initialization.

Related upstream work:

  • #16912 introduced the persistent installation ID and writable-open behavior.
  • #21182 moved resolution to host startup and let internal child sessions reuse the parent's ID. A separately launched CLI still resolves the file itself.
  • #26277 discusses Android file-lock failures in the same startup path; the observed failure here occurs when opening the file for writing on macOS.

Activity

  1. added
    bug
    CLI
    exec
    sandbox
    app-server
    on Sep 3, 2026
  2. fscfede-beep commented on Sep 3, 2026

    @fscfede-beep

    I checked this against current main (1d741742c5fd5d3cf5d93ea71d48a3c9af9bda41), and resolve_installation_id() still opens the file with read(true).write(true).create(true) before it knows whether the existing contents are already a valid UUID.

    A narrow way to preserve the existing creation/repair/concurrency path is a read-only fast path rather than weakening the locked writer path:

    1. attempt a plain read of the existing installation_id;
    2. if it parses as a UUID, return the normalized UUID without requesting write access;
    3. if the file is missing, unreadable as a valid UUID, or needs repair, fall back to the current writable-open + lock + mode-normalization + rewrite logic unchanged.

    That directly addresses the reported read-only-existing-ID case while keeping missing/invalid IDs and concurrent initialization on the existing serialized writer path. A focused regression should make an existing valid ID non-writable and assert reuse succeeds, alongside the existing generate/rewrite tests.

    One caveat worth testing: the read-only fast path is intentionally only an optimization for already-valid state; it should not become a second repair path or claim stronger concurrency semantics than the locked writer path.

    Validation boundary: this is current-source inspection only. I do not have a Rust toolchain in this environment, so I am not claiming cargo check or test pass, and I have not opened a PR/fork.

  3. argszero commented on Sep 3, 2026

    @argszero

    TyceHerrman's report and fscfede-beep's read-only fast-path suggestion are both correct — I implemented and validated that approach on current main (498d40b29f, which has the same read+write+create open in codex-rs/core/src/installation_id.rs).

    The fix adds a read-only fast path before the writable open: if the existing installation_id file parses as a valid UUID, return it without ever requesting write access. Missing / unreadable / invalid ids fall through to the existing locked create/repair path unchanged, preserving the original creation and concurrency semantics.

    Broad note: this repo currently blocks cloning/PR creation via the GraphQL CreatePullRequest API for contributors (I hit the same door earlier this week), so I can't open an upstream PR directly. The validated change is on my fork at argszero/codex branch fix/installation-id-readonly-reuse (PR #1) — happy to hand it off to anyone with write access, or to open one if the gate is lifted.

    Validated against current main:

    • cargo clippy -p codex-core --lib: clean
    • codex-core installation_id unit tests: 5/5 pass (3 pre-existing + new resolve_installation_id_reuses_existing_uuid_when_writes_denied, which chmods an existing valid id to 0o444 — a read-write open then fails with EACCES — and asserts reuse still succeeds)
  4. argszero commented on Sep 3, 2026

    @argszero

    ok

  5. kyle886 commented on Oct 4, 2026

    @kyle886

    Additional reproduction in managed Codex Cloud with codex-cli 0.159.0-alpha.3: a standalone app-server exits before any RPC output.

    The launch used /opt/codex/bin/codex app-server --listen stdio:// with sqlite_home and log_dir explicitly directed to writable workspace directories. The existing Codex home, authentication, and sandbox restrictions were preserved.

    A single bounded filesystem-metadata trace recorded this failed open:

    open("/run/codex-environment/codex-home/installation_id",
         O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC, 0644) = -1 EROFS (Read-only file system)
    

    The native process exited 1. The diagnostic took approximately 0.419 seconds; retained trace and stderr totalled 1,395 bytes. No RPC or model task turn followed.

    The matching upstream tag, rust-v0.159.0-alpha.3, resolves to 3b01b36fa5eb96ba82a776bd3c2fc57f8969181f:

    This trace establishes the denied writable open. It does not establish whether the Cloud installation-ID file already contains a valid UUID, or whether later startup steps would succeed after addressing this failure.

    Our use case requires reading a ready session's configured model and reasoning effort before its first work turn. Is standalone app-server a supported route within Codex Cloud? If so, please provide a supported installation-ID storage or read-only startup mechanism that preserves the existing Codex home. If nested app-server is unsupported, which host API supports creating an idle session and reading its applied settings before starting a turn?

  6. tarskisworld commented on Oct 26, 2026

    @tarskisworld

    Additional reproduction on WSL2 with DrvFS Linux metadata enabled, using the standard desktop-managed backend 0.164.0-alpha.11.1 (Windows app 26.1021.3705.0).

    Two Linux users access the same Windows-backed CODEX_HOME. The existing installation_id is owned by the first user and has mode0644. As the second user, normal app-server initialization fails:

    open("<CODEX_HOME>/installation_id",
         O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC, 0644) = -1 EACCES
    

    The backend exits1 without an initialize result. The matching resolver source requests read/write access before inspecting the existing ID.

    Control: the same backend/profile completes initialize as the second user in Ubuntu WSL, whose Windows-drive mount does not enable metadata and presents the file as owned by its current user. Both tests used user-local SQLite directories and only an initialize request—no model task.

    The failing distro was NixOS 26.05.12658.1f607aa79b63, Nix 2.34.9, on Windows 11 25H2 build 26200.9711. Its mount options included metadata,uid=1000,gid=100; the failing process was UID1001 and the file owner UID1000.

    A separate warning also occurs when chmodding the shared tmp/arg0-linux directory to0700. It should not be confused with the fatal identity-file open; a per-user helper root may need separate coverage.

    This adds a multi-user/DrvFS case supporting the valid-ID read-only path discussed above. Limit: a direct --print-startup-config check passes in both distros; an earlier GUI configuration-read error remains untraced. No credential or identifier contents are included.

  7. ChanwookJeong commented on Nov 17, 2026

    @ChanwookJeong

    Additional macOS file-access reproduction and isolated validation for #42398.

    Environment

    • macOS 27.2.1 (26B131), Apple Silicon
    • Installed Codex CLI 0.165.0-alpha.1.2
    • Same CODEX_HOME, UID and EUID across both file-access probes
    • These probes did not launch Codex; the installed binary remained unchanged.

    Observed file-access behavior

    Operation Restricted ATLAS Lab Normal Mac Terminal
    Open existing installation_id read-only Success Success
    Open existing installation_id read-write EPERM (errno 1) Success

    The existing file's hash and metadata remained unchanged. No file writes, creation, locking, or permission modification were performed during these probes.

    Source inspection

    The source corresponding to the installed Codex version requests read(true).write(true).create(true) before validating the existing installation ID.

    This matches the file-access restriction described in #42398.

    Isolated validation

    A separate Python implementation of read-only reuse passed 16 tests covering valid-ID reuse, missing/invalid IDs, symlink and file-replacement rejection, concurrency, locking, and partial-write failures.

    These results validate an isolated implementation strategy, not an official Rust patch or successful Codex app-server initialization.

    The historical app-server initialization failure remains unresolved. The denied read-write access is a strong candidate for an initialization blocker, but has not been directly established as the failed operation in that historical execution.

    The isolated tests also do not establish safety against all non-cooperating same-UID file modifications or guarantee atomic recovery under every concurrent failure scenario.

    Request

    Could maintainers confirm:

    1. Whether an official read-only reuse fix for an already-valid installation ID is planned or available.
    2. Whether a supported diagnostic method exists to identify additional app-server initialization failures without relaxing the outer sandbox restrictions.

    No production binary, actual installation ID, authentication data, or security configuration was modified.

    No model requests were made during these file-access probes.

  8. removed
    exec
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIapp-serverbugsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions