Repository navigation
Conversation
Codex may exit 0 even when a sandbox policy prevented the requested operation. The failure is only visible in the JSONL event stream. Previously OpenClaw checked only exitCode === 0 and treated these runs as successful, passing the agent's failure reasoning as output. - Add detectSandboxDenied() to scan JSONL records for structured sandbox denial signals (error items, tool outputs, status fields) - Wire into parseCliJsonl() to set sandboxDenied flag on CliOutput - CLI runner throws FailoverError with reason "sandbox_denied" when exit-0 JSONL contains sandbox denial - Add "sandbox_denied" to FailoverReason and AuthProfileFailureReason - Exclude sandbox_denied from auth profile failure tracking (local config issue, not an auth health signal) - 11 regression tests covering detection, false-positive prevention, and JSONL integration Closes openclaw#39317 Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15b25584b0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (!text) { | ||
| return null; | ||
| } | ||
| return { text, sessionId, usage }; | ||
| const sandboxDenied = detectSandboxDenied(records); |
There was a problem hiding this comment.
Run sandbox detection before empty-text JSONL early return
parseCliJsonl returns null whenever no message text is collected, and only runs detectSandboxDenied(records) after that early return. In Codex runs that emit only structured error/tool events (sandbox denial) without a message item, this path drops the new sandboxDenied signal, so runCliAgent sees parsed as null and treats an exit-0 sandbox failure as success. This reintroduces the false-success behavior for a common denial shape and defeats the fix for those cases.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR fixes a real bug where Codex can exit 0 even when a sandbox policy denies a requested operation. The approach is architecturally sound — scanning structured JSONL fields to avoid false positives from agents merely discussing sandboxing — and the plumbing across Critical logic gap to address before merging: The sandbox detection in To fix:
Confidence Score: 2/5
|
| }); | ||
|
|
||
| describe("parseCliJsonl sandbox detection", () => { | ||
| it("sets sandboxDenied when JSONL contains sandbox error item", () => { | ||
| const jsonl = [ | ||
| JSON.stringify({ thread_id: "abc123" }), | ||
| JSON.stringify({ | ||
| item: { | ||
| type: "error", | ||
| text: "sandbox policy: write denied for /workspace/TEST_RO.md", | ||
| }, | ||
| }), | ||
| JSON.stringify({ | ||
| item: { | ||
| type: "message", | ||
| text: "I was unable to write the file due to sandbox restrictions.", | ||
| }, | ||
| }), | ||
| ].join("\n"); | ||
|
|
||
| const result = parseCliJsonl(jsonl, CODEX_BACKEND); | ||
| expect(result).not.toBeNull(); | ||
| expect(result!.sandboxDenied).toBe(true); | ||
| expect(result!.sessionId).toBe("abc123"); | ||
| }); | ||
|
|
||
| it("does not set sandboxDenied for normal output", () => { | ||
| const jsonl = [ | ||
| JSON.stringify({ thread_id: "abc123" }), | ||
| JSON.stringify({ | ||
| item: { type: "message", text: "I've created the file successfully." }, | ||
| }), | ||
| ].join("\n"); | ||
|
|
||
| const result = parseCliJsonl(jsonl, CODEX_BACKEND); | ||
| expect(result).not.toBeNull(); | ||
| expect(result!.sandboxDenied).toBeUndefined(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Both integration tests include at least one type: "message" item alongside the sandbox-denial record, so they always produce non-empty text and never exercise the code path where text is empty. Add a test for denial-only JSONL to expose the early-return gap:
| }); | |
| describe("parseCliJsonl sandbox detection", () => { | |
| it("sets sandboxDenied when JSONL contains sandbox error item", () => { | |
| const jsonl = [ | |
| JSON.stringify({ thread_id: "abc123" }), | |
| JSON.stringify({ | |
| item: { | |
| type: "error", | |
| text: "sandbox policy: write denied for /workspace/TEST_RO.md", | |
| }, | |
| }), | |
| JSON.stringify({ | |
| item: { | |
| type: "message", | |
| text: "I was unable to write the file due to sandbox restrictions.", | |
| }, | |
| }), | |
| ].join("\n"); | |
| const result = parseCliJsonl(jsonl, CODEX_BACKEND); | |
| expect(result).not.toBeNull(); | |
| expect(result!.sandboxDenied).toBe(true); | |
| expect(result!.sessionId).toBe("abc123"); | |
| }); | |
| it("does not set sandboxDenied for normal output", () => { | |
| const jsonl = [ | |
| JSON.stringify({ thread_id: "abc123" }), | |
| JSON.stringify({ | |
| item: { type: "message", text: "I've created the file successfully." }, | |
| }), | |
| ].join("\n"); | |
| const result = parseCliJsonl(jsonl, CODEX_BACKEND); | |
| expect(result).not.toBeNull(); | |
| expect(result!.sandboxDenied).toBeUndefined(); | |
| }); | |
| }); | |
| it("sets sandboxDenied when JSONL has only error items and no message text", () => { | |
| const jsonl = [ | |
| JSON.stringify({ thread_id: "abc123" }), | |
| JSON.stringify({ | |
| item: { | |
| type: "error", | |
| text: "sandbox policy: write denied for /workspace/TEST_RO.md", | |
| }, | |
| }), | |
| ].join("\n"); | |
| const result = parseCliJsonl(jsonl, CODEX_BACKEND); | |
| // Should NOT be null — sandbox denial must be surfaced even without message text. | |
| expect(result).not.toBeNull(); | |
| expect(result!.sandboxDenied).toBe(true); | |
| }); |
Without this fix, the test above would fail because parseCliJsonl returns null.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/cli-runner.sandbox-denied.test.ts
Line: 92-130
Comment:
Both integration tests include at least one `type: "message"` item alongside the sandbox-denial record, so they always produce non-empty `text` and never exercise the code path where `text` is empty. Add a test for denial-only JSONL to expose the early-return gap:
```suggestion
it("sets sandboxDenied when JSONL has only error items and no message text", () => {
const jsonl = [
JSON.stringify({ thread_id: "abc123" }),
JSON.stringify({
item: {
type: "error",
text: "sandbox policy: write denied for /workspace/TEST_RO.md",
},
}),
].join("\n");
const result = parseCliJsonl(jsonl, CODEX_BACKEND);
// Should NOT be null — sandbox denial must be surfaced even without message text.
expect(result).not.toBeNull();
expect(result!.sandboxDenied).toBe(true);
});
```
Without this fix, the test above would fail because `parseCliJsonl` returns `null`.
How can I resolve this? If you propose a fix, please make it concise.Move detectSandboxDenied() before the empty-text early return in parseCliJsonl() so sandbox denials without message-typed items are still surfaced. Addresses Codex review P1 feedback on PR openclaw#39460. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Addressed both Codex review comments in 82a261c: P1 - sandbox denial missed for text-less JSONL: Moved Test coverage gap: Added a new test case ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82a261c927
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (outputMode === "jsonl") { | ||
| const parsed = parseCliJsonl(stdout, backend); | ||
| if (parsed?.sandboxDenied) { |
There was a problem hiding this comment.
Check resume text output for sandbox-denied runs
This new guard only runs in the outputMode === "jsonl" branch, but Codex’s default resume path uses text output (resumeOutput: "text" in src/agents/cli-backends.ts), so resumed sessions still return stdout as success without any sandbox-denied check. In practice, an exit-0 sandbox denial during exec resume will continue to be treated as a successful run, which leaves the false-success behavior in the common follow-up-turn flow.
Useful? React with 👍 / 👎.
| (itemType.includes("tool") || itemType.includes("command") || itemType.includes("action")) && | ||
| typeof item.text === "string" && | ||
| SANDBOX_DENIED_RE.test(item.text) | ||
| ) { |
There was a problem hiding this comment.
Require failure markers before flagging tool output text
This branch marks sandbox denial from any tool/command/action item whose text matches the regex, even when the tool call succeeded, but those text fields can contain arbitrary command/file content. A normal run that reads logs or docs containing phrases like "sandbox policy ... denied" will now be misclassified as sandbox_denied and thrown as a FailoverError, so detection should be gated by explicit error status (for example item.type === "error" or a denied status flag) rather than raw tool output text alone.
Useful? React with 👍 / 👎.
…ool-output false positives
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d80cd24509
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const SANDBOX_DENIED_RE = | ||
| /sandbox.policy|sandbox.denied|sandbox.*read.only|read.only.*sandbox|write.*denied.*sandbox|sandbox.*blocked|permission denied.*sandbox/i; |
There was a problem hiding this comment.
Tighten text-mode sandbox regex to avoid false failovers
The text-path detector currently matches any output containing sandbox policy via sandbox.policy, so a successful resumed Codex run that merely discusses sandbox behavior (for example, answering a user question about policy) is classified as sandbox_denied and thrown as a FailoverError. Because runCliAgent applies this check unconditionally in outputMode === "text", normal responses can be dropped as failures even when no operation was denied.
Useful? React with 👍 / 👎.
| (typeof item.exit_code === "number" && item.exit_code !== 0); | ||
| // Short tool output (<500 chars) with denial keywords is almost certainly | ||
| // a real denial, not a coincidental match in a long log. | ||
| if (hasErrorSignal || item.text.length < 500) { |
There was a problem hiding this comment.
Require explicit error signal for tool-output sandbox detection
This branch still marks sandbox denial when matching text appears in any short (<500 chars) tool/command/action output, even if the tool call succeeded (status not failed and exit_code is 0). Successful commands like rg/cat that print lines containing phrases such as sandbox policy can therefore set sandboxDenied, causing the JSONL path to throw FailoverError on a healthy run.
Useful? React with 👍 / 👎.
- Remove short-text (<500 chars) fallback in tool output detection; now requires explicit error signal (status=error/failed/denied or non-zero exit_code) to flag sandbox denial from tool/command items - Use stricter regex for text-mode detection to avoid false positives when resumed Codex output merely discusses sandbox concepts - Update tests to reflect tighter detection requirements Co-Authored-By: Claude Opus 4.6 <[email protected]>
🔒 Aisle Security AnalysisWe found 3 potential security issue(s) in this PR:
1. 🟡 Memory exhaustion risk in parseCliJsonl from retaining all parsed JSONL records
DescriptionThe This is uncontrolled resource consumption because:
If the CLI produces many JSONL events or very large JSON objects (e.g., long tool output embedded in JSONL), this can significantly increase peak memory and can crash the Node process (DoS). Vulnerable code: const texts: string[] = [];
const records: Record<string, unknown>[] = [];
for (const line of lines) {
...
records.push(parsed);
...
}
const sandboxDenied = detectSandboxDenied(records);RecommendationAvoid retaining the full JSONL record set. Perform sandbox-denied detection incrementally while parsing, or refactor Example (online detection without storing let sandboxDenied = false;
for (const line of lines) {
let parsed: unknown;
try {
parsed = JSON.parse(line);
} catch {
continue;
}
if (!isRecord(parsed)) continue;
// incremental detection
if (!sandboxDenied && detectSandboxDenied([parsed])) {
sandboxDenied = true;
}
// existing extraction logic...
}Better (no per-iteration array allocation): function detectSandboxDeniedRecord(rec: Record<string, unknown>): boolean {
// move the body of the loop from detectSandboxDenied here
}
let sandboxDenied = false;
...
if (!sandboxDenied && detectSandboxDeniedRecord(parsed)) sandboxDenied = true;Additionally, consider implementing an upper bound on captured stdout/stderr (truncate after N bytes) to prevent output-based memory DoS across the whole CLI runner. 2. 🟡 Unbounded CLI stdout scanned with backtracking regex can cause resource-exhaustion DoS
DescriptionThe CLI runner performs sandbox-denied detection by running regular expressions containing multiple Why this is risky:
Vulnerable code (regex + unbounded test): const SANDBOX_DENIED_TEXT_RE =
/sandbox policy:\s*.+? denied|permission denied.*sandbox|write.*denied.*sandbox|read.only.*sandbox/i;
export function detectSandboxDeniedInText(text: string): boolean {
return SANDBOX_DENIED_TEXT_RE.test(text);
}This is reachable from the CLI hot path:
Impact:
RecommendationMitigate uncontrolled resource usage by bounding the scanned input and avoiding backtracking-heavy patterns. Suggested hardening (combine as appropriate):
const MAX_SCAN_CHARS = 64_000;
const window = text.length > MAX_SCAN_CHARS ? text.slice(-MAX_SCAN_CHARS) : text;
return SANDBOX_DENIED_TEXT_RE.test(window);
const lower = window.toLowerCase();
if (lower.includes("sandbox policy:") && lower.includes(" denied")) return true;
if (lower.includes("permission denied") && lower.includes("sandbox")) return true;
{
const iWrite = lower.indexOf("write");
if (iWrite >= 0) {
const iDenied = lower.indexOf("denied", iWrite);
if (iDenied >= 0 && lower.indexOf("sandbox", iDenied) >= 0) return true;
}
}
return false;
3. 🟡 Untrusted CLI stdout triggers sandbox_denied FailoverError and model/provider failover
DescriptionThe CLI runner treats model-controlled output text as a security signal for In
This creates a reliance on untrusted input for a security-relevant decision (failover/provider switching) and enables:
Vulnerable code (text-mode): if (outputMode === "text") {
if (detectSandboxDeniedInText(stdout)) {
throw new FailoverError(...{ reason: "sandbox_denied", ... });
}
return { text: stdout, sessionId: undefined };
}The detection is purely regex-based: const SANDBOX_DENIED_TEXT_RE =
/sandbox policy:\s*.+? denied|permission denied.*sandbox|write.*denied.*sandbox|read.only.*sandbox/i;Because this runs on raw assistant text, the condition can be satisfied without any real sandbox policy violation. RecommendationDo not make failover/provider-switch decisions based on untrusted assistant text. Recommended hardening (pick one or combine):
Example: stop falling back on sandbox_denied (illustrative): // in model-fallback runner error handling
if (isFailoverError(normalized) && normalized.reason === "sandbox_denied") {
throw normalized; // do not attempt other candidates
}And/or change Codex backend to avoid Analyzed PR: #39460 at commit Last updated on: 2026-03-10T03:33:13Z |
|
Addressed remaining P2 bot feedback in 3745049: P2 - Tool output false positives: Removed the P2 - Text-mode regex too broad: Created a stricter Updated all affected test cases to reflect the tighter detection requirements. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3745049148
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| * Codex output merely discusses sandbox behavior. | ||
| */ | ||
| const SANDBOX_DENIED_TEXT_RE = | ||
| /sandbox policy:\s*\S+ denied|permission denied.*sandbox|write.*denied.*sandbox|read.only.*sandbox/i; |
There was a problem hiding this comment.
Match path-bearing sandbox policy denials in text mode
The text-mode detector regex is too narrow: sandbox policy:\s*\S+ denied only matches a single token before denied, so strings like sandbox policy: write to /workspace/file denied (the same denial wording already used in your JSONL tests) are missed. Because Codex resume defaults to outputMode === "text", this leaves a real exit-0 sandbox-denied path unflagged and still treated as success.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 6ebd045 - widened the text-mode regex from \S+ (single token) to .+? (multi-word match) so path-bearing denials like sandbox policy: write to /workspace/file denied are now caught. Added a test covering this case.
The \S+ pattern only matched a single token before "denied", missing denials like "sandbox policy: write to /workspace/file denied". Changed to .+? to match path-bearing sandbox policy denials. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Closing to reduce noise on the review queue. The fix is available on my fork if it becomes relevant. Happy to reopen or resubmit if there's interest. |
Summary
Closes #39317.
Codex may exit 0 even when a sandbox policy prevented the requested file write. OpenClaw only checked
exitCode === 0and treated these runs as successful, passing the agent's internal failure reasoning as normal output. This causes subagent orchestration to record work as completed when nothing actually happened.Changes:
detectSandboxDenied()to scan structured JSONL records for sandbox denial signals (error items, tool-call outputs, status fields) without false-positiving on agents that merely discuss sandboxingparseCliJsonl()to setsandboxDeniedflag onCliOutputFailoverErrorwith reason"sandbox_denied"when exit-0 JSONL contains sandbox denial"sandbox_denied"toFailoverReasonandAuthProfileFailureReasontypessandbox_deniedfrom auth profile failure tracking (local config issue, not an auth health signal)sandbox_deniedto HTTP 403 inresolveFailoverStatusDesign decisions
detectSandboxDenied()scansitem.type === "error", tool/command/action item types,item.status, and top-levelerrorfields. It does NOT scanitem.type === "message"text, preventing false positives when agents discuss sandbox concepts."timeout"inresolveAuthProfileFailureReason().Testing
cli-runner.sandbox-denied.test.ts:detectSandboxDenied: top-level error string, nested error.message, error-typed items, tool-call outputs, command actions, status fields, and three false-positive prevention casesparseCliJsonlintegration: sandbox error + exit 0 sets flag, normal output does notFiles changed
src/agents/cli-runner/helpers.tsdetectSandboxDenied(),sandboxDeniedflag onCliOutputsrc/agents/cli-runner.tssandboxDeniedafter exit-0 JSONL parse, throwFailoverErrorsrc/agents/failover-error.tssandbox_deniedto 403src/agents/pi-embedded-helpers/types.ts"sandbox_denied"toFailoverReasonsrc/agents/auth-profiles/types.ts"sandbox_denied"toAuthProfileFailureReasonsrc/agents/pi-embedded-runner/run.tssandbox_deniedfrom auth profile failure statesrc/agents/cli-runner.sandbox-denied.test.tsPost-Deploy Monitoring & Validation
sandbox_deniedfailover reason after deploying--sandbox workspace-writevsread-only) if they see unexpected failures