Skip to content

[Bug]: OpenClaw treats codex exec sandbox-denied runs as success because codex exits 0 #39317

Closed

Description

@sebastianlang84

Bug type

Behavior bug (incorrect output/state without crash)

Summary

OpenClaw can treat failed codex exec --json runs as successful because Codex may emit sandbox/write-denied failure information in JSONL agent output while still exiting with status code 0.

Steps to reproduce

  1. Use OpenClaw 2026.3.2 with the built-in codex-cli backend.
  2. Trigger a Codex-backed subagent write task in an effective read-only Codex sandbox, or reproduce directly with Codex:
    codex exec "Write a new file named TEST_RO.md with the content 'hello'." --json --color never --sandbox read-only --skip-git-repo-check
  3. Observe that no file is created.
  4. Observe that Codex emits JSONL events describing the write failure as agent output.
  5. Observe that the Codex process still exits with EXIT_CODE=0.
  6. In OpenClaw, the run can then be interpreted as completed/successful even though the requested mutation never happened.

Expected behavior

OpenClaw should inspect Codex JSONL output for failed action/tool signals and propagate the run as failed when the underlying file mutation or command execution was denied or rejected.

Actual behavior

A Codex run can fail semantically while still looking successful to OpenClaw because:

  • the process exit code is 0
  • the failure is surfaced only in JSONL event content
  • no file is actually created or modified

This can cause subagent orchestration to record a run as completed even though the requested write never happened.

OpenClaw version

2026.3.2 (52a583035f)

Operating system

Debian GNU/Linux 13 (trixie)

Install method

Local source checkout / dev run

Logs, screenshots, and evidence

Direct Codex repro:

codex exec "Write a new file named TEST_RO.md with the content 'hello'." --json --color never --sandbox read-only --skip-git-repo-check

Observed:
- No file created
- Codex JSONL includes an agent message explaining the write was blocked by a read-only filesystem / write approval policy
- Process exit code is still 0

Control repro:
- Same command with --sandbox workspace-write creates the file successfully

Impact and severity

Affected: Users relying on Codex-backed subagents or Codex fallback runs for coding/file tasks
Severity: High, because failed work can be misreported as successful
Frequency: Reproducible whenever Codex surfaces the failure only through JSONL content while exiting 0
Consequence: Silent false positives in subagent execution, misleading summaries, and harder debugging of failed automation

Additional information

A robust fix is to parse Codex JSONL for failed command_execution / shell_command / file_change items and known sandbox-denied agent messages instead of relying only on process exit status.

Activity

  1. changed the title [-]OpenClaw treats codex exec sandbox-denied runs as success because codex exits 0[/-] [+][Bug]: OpenClaw treats codex exec sandbox-denied runs as success because codex exits 0[/+] on Mar 8, 2026
  2. rnrnstar2 commented on Mar 8, 2026

    @rnrnstar2

    Priority: P1 - 実行状態管理の欠陥。サンドボックス拒否を成功と誤認し、セキュリティリスクとデバッグ困難性を引き起こす。

  3. rnrnstar2 commented on Mar 8, 2026

    @rnrnstar2

    🔥 P1 Priority - OpenClaw treats codex exec sandbox-denied runs as success because codex exits 0. This causes silent failures in subagent workflows. Requires exit code handling fix.

  4. added a commit that references this issue on Mar 8, 2026
    15b2558
  5. mvanhorn commented on Mar 8, 2026

    @mvanhorn
    Contributor

    Submitted a fix in #39460.

    The approach: scan structured JSONL fields (error items, tool-call outputs, status fields) for sandbox-denied signals after Codex exits 0. When detected, the CLI runner throws a FailoverError with reason "sandbox_denied" instead of passing the agent's failure reasoning as successful output.

    Key design choice: detection only checks structured fields (item.type === "error", tool/command items, top-level error), not regular message text. This prevents false positives when an agent merely discusses sandboxing without actually being denied.

    Also added "sandbox_denied" as a new FailoverReason (mapped to 403) and excluded it from auth profile failure tracking since it's a local config issue.

    11 regression tests covering detection and false-positive prevention.

  6. openclaw-barnacle commented on Apr 23, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  7. added
    stale
    on Apr 23, 2026
  8. clawsweeper commented on Apr 26, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

    Current main resolves the reported built-in codex-cli false-success path by removing the bundled direct Codex CLI backend and routing legacy Codex CLI refs to the Codex app-server runtime. The earlier structured-JSONL fix attempt is useful context, but the supported core path no longer executes codex exec --json through a bundled codex-cli backend.

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review details

    Best possible solution:

    Keep the Codex app-server migration as the supported OpenAI Codex path, and treat any future false-success report for an explicit custom CLI backend as a new plugin-owned or generic CLI contract issue with current-main config evidence.

    Do we have a high-confidence way to reproduce the issue?

    No current-main reproduction remains for the reported built-in codex-cli path. Current source and docs show that OpenClaw no longer bundles that backend and migrates legacy Codex CLI refs to the Codex app-server route.

    Is this the best way to solve the issue?

    Yes, for the reported supported core path. Removing the bundled direct Codex CLI route is the narrower maintainable core solution; Codex-specific JSONL failure parsing should only return if a supported plugin/runtime contract needs it.

    Security review:

    Security review cleared: No PR diff is under review; the sandbox-denial false-success concern is addressed on current main by removing the affected bundled runtime path.

    What I checked:

    Likely related people:

    • steipete: Peter Steinberger authored the earlier codex-cli sandbox-default change and later introduced/maintained the Codex app-server harness work that now owns the supported Codex route. (role: introduced behavior and adjacent owner; confidence: high; commits: 5b257c65d5a7, dd26e8c44d4e, 58f1db1bc8eb; files: src/agents/cli-backends.ts, extensions/codex/openclaw.plugin.json, extensions/codex/src/app-server/run-attempt.ts)
    • ragesaq: Authored the merged OpenAI Codex runtime provider-routing PR near the current app-server route and OAuth bootstrap surface. (role: recent area contributor; confidence: medium; commits: 58f1db1bc8eb; files: src/agents/openai-codex-routing.ts, src/agents/pi-embedded-runner/run.ts, docs/plugins/codex-harness.md)
    • vincentkoc: Added the recent changelog entry for OpenAI Codex runtime routing and OAuth bootstrap, and prior ClawSweeper context tied current Codex routing docs to this area. (role: recent docs/release contributor; confidence: medium; commits: 684a6303b34c; files: CHANGELOG.md, docs/gateway/cli-backends.md, docs/concepts/model-providers.md)
    • mvanhorn: Authored the closed structured JSONL sandbox-denial PR and issue comment explaining the alternative sandbox_denied failover design. (role: prior fix proposer; confidence: medium; commits: 15b25584b029, 82a261c92701, d80cd24509c6; files: src/agents/cli-runner.ts, src/agents/cli-runner/helpers.ts, src/agents/failover-error.ts)

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 8dc213227bee; fix evidence: commit b7893fc1586c, main fix timestamp 2026-05-17T05:09:05Z.

  9. removed
    stale
    on Apr 26, 2026
  10. added
    P1
    impact:security
    impact:session-state
    on May 16, 2026
  11. locked as resolved and limited conversation to collaborators on May 20, 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

    P1impact:securityimpact:session-state

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions