Skip to content

fix(cli): a sandbox that denies chmod no longer breaks reading Orca's state files - #33662

Merged
nwparker merged 1 commit into
mainfrom
nwparker/agint-agent-sandbox-runtime-ipc
Oct 25, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/agint-agent-sandbox-runtime-ipc

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​12

ELI5

If you let an agent's sandbox reach Orca's socket, orca status said "ready" but orca worktree list still failed, saying orca-environments.json was "invalid". The file was fine. Before reading it, the CLI tries to tighten its permissions with chmod, and the sandbox blocks that write. Now a blocked chmod no longer fails the read.

Root cause

  • The CLI's state readers (readEnvironmentStoreRecords, the environment sidecar, the WSL/ephemeral-VM stores) call hardenExistingSecureFile first. On POSIX that calls chmodSync on userData and on the file. The read path wraps it in the same try as the parse, so an EPERM from chmod comes out as runtime_error: Could not read Orca environments at …; the file is invalid.
  • Claude Code's Bash sandbox is @anthropic-ai/sandbox-runtime. On macOS it only allows file-write* (which includes chmod's file-write-mode) inside allowWrite (dist/sandbox/macos-sandbox-utils.js:705-733, v0.0.81). It blocks unix sockets unless the path is in allowUnixSockets (:969-979). So once a user allows Orca's socket, status works but every command that reads environments fails.
  • The modes are already 0700/0600, so the chmod is a no-op attempt. Windows readers were already best-effort (hardenExistingWindowsFile returns a boolean instead of throwing). Only POSIX failed the read.

What changed

  • hardenExistingSecureFile (called only by readers) now ignores EPERM/EACCES/EROFS from hardening. Other errors still throw. Writers (writeSecureFile) are unchanged and still harden and report.
  • Added one regression test: a denied chmod lets the reader continue, and EIO still throws.

How verified

Real CLI built from this branch (out/cli), run under srt 0.0.81 on macOS against a live Orca, with only the runtime socket in allowUnixSockets and writes limited to a temp dir:

command origin/main this PR
orca status --json ok, ready ok, ready
orca worktree list --json runtime_error "orca-environments.json … the file is invalid" ok, 200 worktrees
orca repo list --json, orca terminal list --json — ok

With the socket not allowed, both builds return runtime_access_denied from status and from every other command (the behavior from #22341). File modes stayed 0600 after the runs.

Windows (awin, Orca 1.4.237, Codex 0.159.2 [windows] sandbox = "elevated"), for the related #13539: from inside codex sandbox, the runtime pipe connect returns EPERM. orca status --json, orca worktree list --json and plain orca worktree list all return runtime_access_denied with the "don't restart" next steps. So the "status says starting forever" half of #13539 is already fixed on main by #22341. The pipe DACL half is not addressed here; see below.

pnpm tc, pnpm test src/shared/secure-file*.test.ts src/shared/runtime-environment* src/cli/runtime/environments.test.ts, pnpm run check:code-quality:changed all pass.

Risk

Low. Only reader-side, opportunistic hardening changes. A file with loose permissions that a sandboxed reader can't chmod is read as-is and gets hardened on the next unsandboxed read or write.

Not in this PR

#13539 Defect 1 (sandbox users can't connect to the Windows runtime pipe) needs a product/security decision. Fixing it means creating the pipe with a native security descriptor that grants CodexSandboxUsers connect rights. That would let sandboxed commands drive Orca, and Orca can spawn arbitrary terminals, so it is effectively a sandbox escape the user opted out of.

Fixes #20937

@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 534af424-1b42-4261-a0c3-ce85a66f00cb
Commits

Reviewing files that changed from the base of the PR and between 47ed6e1 and e7ef1dd.

Files selected for processing: 2
  • src/shared/secure-file.test.ts
  • src/shared/secure-file.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit f94b15e into main Oct 25, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: macOS: runtime-dependent CLI commands fail from Claude Code's Bash sandbox with "Orca is not running" while orca status reports ready

1 participant