Skip to content

Code Mode nested exec_command ignores allow rules and require_escalated on macOS #32848

Open

Description

@Casey-Bates

What version of Codex CLI is running?

codex-cli 0.144.3

Which model were you using?

gpt-5.6-sol with high reasoning effort

What platform is your computer?

macOS 26.5.1 (25F80), Apple Silicon (arm64)

What issue are you seeing?

In Code Mode on macOS, shell commands are invoked through an outer functions.exec custom tool call and an inner tools.exec_command. The inner command stays under the outer Seatbelt sandbox even when:

  1. it matches an explicit allow rule, or
  2. it is retried with sandbox_permissions: "require_escalated".

The initial .git write failure under the workspace profile is expected because .git is a protected path. The bug is that the approved/allowed escalation does not lift that restriction.

The rollout records the nested call and an immediate failure, but no approval request/decision event for the inner command. Outer telemetry identifies only tool_name=exec.

Original affected thread: 019f5c9b-6f72-74f0-9f6d-d3fa9f743897

Effective configuration

default_permissions = "workspace"
approval_policy = "on-request"
approvals_reviewer = "auto_review"

The repository is trusted and the workspace root is writable. Global rules include:

prefix_rule(pattern=["git", "add"], decision="allow")
prefix_rule(pattern=["git", "commit", "-m"], decision="allow")

There is no local requirements.toml and no explicit .git deny rule.

What steps can reproduce the bug?

  1. Start Codex on macOS with the workspace permission profile.
  2. In Code Mode, invoke:
    const r = await tools.exec_command({
      cmd: "git add --refresh -- tests/test_ui_claude_agent_stream.py",
      workdir: "/Users/<user>/<repo>"
    });
  3. Observe the expected protected-path failure for .git/index.lock.
  4. Retry the same inner call with:
    sandbox_permissions: "require_escalated",
    justification: "Allow the explicitly authorized git index refresh.",
    prefix_rule: ["git", "add"]
  5. Observe the same Seatbelt denial immediately, without an approval event.

A fresh controlled nested-Codex diagnostic reproduced the propagation problem more minimally. Both the normal and escalated inner commands exited in about 0.1 seconds with:

sandbox-exec: sandbox_apply: Operation not permitted

The original thread produced:

fatal: Unable to create '/Users/<user>/<repo>/.git/index.lock': Operation not permitted

An escalated direct probe such as touch .git/codex-write-probe also remained denied.

What is the expected behavior?

A nested command matching an allow rule, or a command whose require_escalated request is approved, should execute outside the workspace Seatbelt restriction. If escalation cannot be honored through Code Mode, the inner request should be surfaced as rejected/unsupported instead of silently running with the original sandbox.

Additional information

Read-only Git operations work. The same Git binary and repository work outside the Codex shell, and GitHub Desktop can update the repository metadata normally. File ownership, ACLs, flags, stale locks, and alternate Git binaries were ruled out.

Related but distinct:

Activity

  1. added
    bug
    CLI
    sandbox
    tool-calls
    on Jul 13, 2026
  2. sixbangs commented on Sep 13, 2026

    @sixbangs

    Seeing the same behavior with 1Password CLI on macOS. Through functions.exec → tools.exec_command, this still fails:

    await tools.exec_command({
        cmd: "op vault list --format=json > /dev/null",
        sandbox_permissions: "require_escalated",
        justification: "Test 1Password desktop connectivity outside the sandbox",
        tty: true,
        login: false,
    });

    The host's kernel log confirms:

    Sandbox: op(52820) deny(1) mach-lookup 2BUA8C4S2C.com.1password.browser-helper
    

    An explicitly escalated diagnostic also returned sandbox_check: 1; /usr/bin/log reported Cannot run while sandboxed. op works in a normal terminal. Restarting the app and resuming the session did not help.

    App: 26.901.51231 (8109), bundle com.openai.codex. 1Password: 8.12.36; CLI: 2.34.1. Workspace permission profile with auto_review.

  3. OskarSwierad commented on Sep 15, 2026

    @OskarSwierad

    I can reproduce this on Linux Codex CLI, so the issue is not macOS-specific.

    Environment

    • Codex CLI: 0.154.0, installed via curl
    • Codex Desktop build: 26.908.40834
    • OS: CachyOS Linux, AMD Ryzen PC workstation
    • Kernel: 7.2.5-1-cachyos
    • Model: gpt-5.6-sol
    • Managed permission profile (via config.toml) with the active workspace writable

    Reproduction

    A normal Code Mode call failed as expected because .git is protected:

    const r = await tools.exec_command({
      cmd: 'git add convert.py && git commit -m "Improve text redaction and headings"',
      workdir: "/home/oskar/xxxx_project/"
    });

    fatal: Unable to create '.git/index.lock': Read-only file system

    The agent then retried through the same outer functions.exec call with:

    sandbox_permissions: "require_escalated",
    justification: "Allow Git to write repository metadata and create the requested commit?",
    prefix_rule: ["git", "commit"]

    After my approval, the inner command still received:

    fatal: Unable to create '.git/index.lock': Read-only file system

    It also retried git add convert.py separately with require_escalated. The command prefix was saved as approved, but .git/index.lock remained read-only.

    Running the identical Git commands outside the Codex conversation succeeded immediately.

    This appears to be the same nested-sandbox propagation problem described in this issue? Basically, the approval flow runs, but the inner tools.exec_command remains confined by the outer Code Mode sandbox. On Linux, .git is mounted read-only rather than producing the macOS Seatbelt error.


    Config

    model = "gpt-5.6-sol"
    model_reasoning_effort = "low"
    model_instructions_file = "/home/oskar/.codex/AGENTS.md"
    default_permissions = "project-only"
    model_reasoning_summary = "detailed"
    service_tier = "default"
    
    # ...
    
    [permissions.project-only]
    description = "Only the active project."
    
    [permissions.project-only.workspace_roots]
    "." = true
    
    [permissions.project-only.filesystem]
    ":minimal" = "read"
    "/home/oskar/.codex/packages/standalone/releases/" = "read"
    glob_scan_max_depth = 32
    
    [permissions.project-only.filesystem.":workspace_roots"]
    "." = "write"
    "**/.stfolder" = "deny"
    "**/.obsidian" = "deny"
    
    [permissions.project-only.network]
    enabled = true
    
    [permissions.project-only.network.domains]
    "*" = "allow"
  4. OskarSwierad commented on Sep 18, 2026

    @OskarSwierad

    I worked around it by explicitly granting .git write access in my named permission profile:

    [permissions.project-only.filesystem.":workspace_roots"]
    "." = "write"
    ".git" = "write"

    I then verified it in a temporary repository, first with actual ChatGPT Desktop, then with:

    codex sandbox -P project-only -C <test-repo> \
      sh -c 'git add probe.txt'

    Result:

    PASS: sandbox can write .git/index
    

    So the explicit .git permission works on Linux and avoids the failing escalation path. However, require_escalated itself still appears not to propagate through the Code Mode outer exec / inner exec_command boundary.

  5. jason21wc commented on Sep 30, 2026

    @jason21wc

    Additional macOS reproduction, with an important denied-read-policy caveat.

    Our commands use the same functions.exec → tools.exec_command path described here. Direct execution of:

    /bin/ps -p $$ -o pid=,ppid=,comm=

    fails inside Codex with exit 127 and operation not permitted: /bin/ps. The identical command in ordinary Terminal succeeds and prints the current zsh PID, parent PID, and /bin/zsh. This is a direct invocation, not merely a Homebrew/RVM startup warning.

    Earlier normal and sandbox_permissions: "require_escalated" attempts both failed. No automatic approval-review rejection was returned; we cannot establish that unrestricted execution was actually attempted. Codex's /usr/bin/log show also returns exit 64, log: Cannot run while sandboxed, matching the September 13 comment above.

    Environment and evidence:

    • macOS 27.0, build 26A428, Apple Silicon.
    • Installed app metadata checked September 28: 26.924.22138, build 11645. The running process's exact bundled Codex revision is unverified.
    • Active managed/restricted profile has explicit protected-path read denials; approval reviewer is auto_review.
    • /bin/ps is setuid-root on this host; relevance to the exact denial is unproven.
    • Bash, zsh and ordinary Git operations work.
    • Fresh direct failure: September 28, 2026, 20:40:39 MDT. A user-run unified-log query covering 20:40:30–20:41:00, including info/debug and filtering messages for deny and ps, returned no matching events. This is inconclusive, not proof that no denial occurred.

    Caveat: upstream sandboxing code deliberately preserves sandboxing during escalation when denied-read rules exist. That may explain our escalation result independently of the propagation defect reported here. We have not matched the running binary to that revision and are not claiming an identical root cause.

    Related symptom reports: #8104 and #4620. The latter's startup workarounds do not establish a fix for direct ps execution.

    Could maintainers clarify whether narrow read-only process inspection is supported while retaining denied-read protections, and whether this reproduction belongs to this issue or intentional policy behavior? If intentional, an actionable explanation when escalation retains the sandbox would help distinguish it from a failed approval path. No protected-path rules or other security controls were removed for this investigation.

  6. TyceHerrman commented on Oct 20, 2026

    @TyceHerrman

    Reproduced on macOS with Codex Desktop’s bundled 0.163.0-alpha.10.2, on-request approvals, auto_review, and a workspace profile containing credential-read denies.

    With this saved rule:

    prefix_rule(pattern=["git", "switch"], decision="allow")

    Calling git switch -c test/probe through functions.exec → tools.exec_command with sandbox_permissions: "require_escalated" failed immediately when creating the Git reference lock. In the same session, escalated git branch test/probe-other succeeded; no saved rule allowed git branch. Explicit command-scoped Git write grants also allowed git switch -c to succeed.

    The approval logic and sandbox selection appear to explain this: the saved allow rule skips fresh approval, leaving already_approved = false, but escalation with read denies requires that approval to broaden writes. The explicit escalation request therefore retains the original restrictions.

    #54440 may share this cause, although I haven’t reproduced its Windows case.

    Could an explicit escalation request trigger filesystem approval even when the command is already allowlisted, or clearly report that broader access wasn’t granted?

  7. m-szymanska commented on Nov 21, 2026

    @m-szymanska

    I can reproduce this in the desktop app on Apple Silicon (macOS 27.3, app 26.1117.31558, bundled Codex CLI 0.171.0-alpha.13) with an on-request approval policy.

    The probe uses only a profile that denies networking and a no-op executable. It does not read user files or change settings:

    /usr/bin/sandbox-exec -p '(version 1) (allow default) (deny network*)' /usr/bin/true
    Context Result
    Ordinary macOS terminal Exit 0
    The same probe launched under codex sandbox from that terminal Exit 71
    Desktop Code Mode functions.exec → tools.exec_command, with sandbox_permissions: "require_escalated" and approval Exit 71

    Both failures report sandbox-exec: sandbox_apply: Operation not permitted. The terminal control reproduces the same error when a parent sandbox is already active. It does not identify a Code Mode approval propagation bug by itself. This desktop profile contains explicit denied reads. In the exact bundled version, sandbox_override_for_first_attempt deliberately retains a filesystem sandbox after approval when denied reads must be enforced. I have not verified that the desktop failure also occurs with a policy that has no denied reads.

    A practical example is Homebrew’s sandboxed bottle extraction. The approved upgrade stops at extraction with exit 71. For a profile with denied reads, the compatibility gap is that an approved tool can still need to establish its own Seatbelt profile. If nested sandboxing cannot be composed safely, an explicit unsupported-operation error would distinguish this case from approval loss. Any functional fix must preserve denied reads inside the approved execution path itself. For a separate no-denied-read profile, the same probe can verify whether the requested escalation actually reaches the executor.

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

    CLIbugsandboxtool-calls

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions