Skip to content

Daemon: sandbox a bot's commands, writes and edits as Codex does - #265

Merged
lydakis merged 7 commits into
mainfrom
claude/project-thread-6zwinw
Oct 28, 2026
Merged

lydakis merged 7 commits into
mainfrom
claude/project-thread-6zwinw

Conversation

@lydakis

@lydakis lydakis commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

This is the daemon half of the sandboxing design: lead and task sandboxes, aligned with Codex. Sonny's half comes next in its own PR.

What changes

  • New bot settings: --sandbox read-only|workspace-write|danger-full-access, --writable PATH (repeatable, made absolute) and --network.
    • They're stored like the other bot settings. A fork copies them, and inspect and ls report them.
    • writable and network require workspace-write.
    • A writable folder is stored by its real path, and a missing one is path_not_found. There are at most 64, taking 32 KiB of JSON.
  • Confinement (src/sandbox.rs): shell (foreground, background, lifted and detached) runs under bubblewrap on Linux and Seatbelt on macOS. The bwrap arguments and the Seatbelt profile are ported from Codex's linux-sandbox and sandboxing crates. Its three .sbpl files are copied verbatim (see NOTICE).
    • Writable: workspace-write can write the bot's folder, the writable folders, $TMPDIR and /tmp.
    • Read-only inside a writable folder: .git (and a worktree's gitdir when the folder holds it), .agents, .codex, .aws, and the store's files.
    • Kept from being made: a missing .git, .agents or .codex.
    • Refused: a protected folder that is a symlink gives sandbox_unavailable.
    • Network: off unless --network.
    • The daemon's socket is out of reach, network on or off, the way Codex keeps its own from a sandboxed command. On Linux, /dev/null is bound read-only over it; on macOS, Seatbelt denies it. Nothing confined can drive the daemon, so a sandboxed bot delegates through tools its client declares.
    • bubblewrap: found only at fixed system paths, never on PATH, and probed once on a blocking worker.
  • write and edit: a confined call is checked against the same folders by its real path, and a denied one gives write_denied.
    • The write itself then runs inside the sandbox, the way Codex runs apply_patch. The daemon starts the agent binary as agent --agent-run-as-write PATH under bwrap or Seatbelt, with the content on stdin. That way a link swapped in after the check can't carry the write out.
    • It takes a process slot, as a command does.
  • Only escapes are gated, as in Codex. A sandboxed bot's shell schema shows Codex's sandbox_permissions and justification fields. An escape is either a shell call with "require_escalated", or a write/edit that names a path outside the writable folders.
    • An escape waits on the bot's gate. If allowed, it runs unconfined.
    • With no gate there is no one to ask, so it is refused, as Codex does under a policy that never asks. A command gets escalation_refused; a write stays confined and gets write_denied.
    • A confined call never waits for a verdict, even when its tool is gated.
    • Whether a call escapes is read from its arguments and the folder names alone, so the round that announces a call and the run that starts it always agree.
  • Inheritance. A bot that a sandboxed bot makes (created_by) or forks takes the creator's sandbox and writable folders unless it names a stricter sandbox. It reaches the network only if both do. This is how Codex's subagents inherit their parent's sandbox.
  • No silent fallback. Creating a sandboxed bot where no sandbox can run gives sandbox_unavailable: no bwrap, user namespaces off, or no /usr/bin/sandbox-exec.
  • Linux placeholders. bubblewrap makes an empty folder on the host to mount a missing .git read-only over.
    • The daemon removes it once no running sandbox holds it. A detached command holds it until it exits.
    • The lock covers only the in-memory list. A sandbox that needs a placeholder that's being removed waits for the removal to finish.
  • Runtime thread. Policy construction, path checks, create-time checks and placeholder removal all run on blocking workers.
  • CI installs bubblewrap in both jobs and allows unprivileged user namespaces, which Ubuntu 24.04 blocks by default. It sets AGENT_TEST_SANDBOX=1 so the sandbox tests fail rather than skip.
$ agent run --help
  --sandbox MODE               A new bot's command sandbox: read-only, workspace-write or danger-full-access; default none
  --writable PATH              Another folder a workspace-write bot may change; repeat for more
  --network                    A workspace-write bot's commands may use the network

Performance

Matched screens against main are recorded in docs/DAEMON_MEASUREMENTS.md under "Sandbox (#265)".

  • Latency, CPU and store jobs per turn: both builds fall within each other's ranges.
  • Idle RSS: 0.4 MiB higher on the branch, all of it the larger binary's resident pages. The heap is the same.

Not in this PR

Tests

  • Rust tests with real bwrap:
    • Roots are written. Writes elsewhere, to .git, to the store and to a fresh .git are refused.
    • The placeholder is removed after the command.
    • Only loopback is reachable.
    • The daemon's socket is unreachable with network off and on, while the same connect works unconfined.
    • write/edit give write_denied, including through a symlink out and a dangling link.
    • Read-only writes nothing, and the in-sandbox write helper itself gets write_denied.
  • Unit tests:
    • Escape rules.
    • The deepest root decides.
    • Seatbelt keeps an inner root's .git, paths go in only as parameters, and the socket deny is present.
    • A symlinked .git refuses.
  • Store tests:
    • A sandboxed bot with gates announces only its escapes.
    • A bot made by a sandboxed bot is no less sandboxed.
  • Runtime tests (real daemon):
    • With a gate, the confined command runs without a verdict and can't write outside. The escaped command and the outside write are announced, and once allowed they run unconfined.
    • With no gate, both are refused.
  • The full runtime suite, cargo test --workspace with AGENT_TEST_SANDBOX=1, clippy and fmt pass locally.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T04:27:22.613323Z e588ccb New commits
🔒 Security Review ✅ Completed 2026-10-28T04:26:49.328890Z e588ccb New commits

Security findings

Advisory findings (6)

ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85e2ca3961

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sandbox.rs Resolved
Comment thread src/server/turn.rs Resolved
Comment thread src/server/turn.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 85e2ca3961

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/store/db.rs Resolved
Comment thread src/sandbox.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc13380ceb

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools.rs Resolved
Comment thread src/store/db.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: fc13380ceb

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/store/db.rs Resolved
Comment thread src/tools.rs Resolved
@lydakis
lydakis force-pushed the claude/project-thread-6zwinw branch from 012daeb to f6de576 Compare October 28, 2026 03:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6de576508

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sandbox.rs Resolved
Comment thread src/sandbox.rs Resolved
Comment thread src/tools/files.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: f6de576508

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/sandbox.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a219bc807

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
Comment thread src/sandbox.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0760bd8626

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
Comment thread src/tools.rs Resolved
…s; children inherit the sandbox without ceilings; take placeholders before a process slot

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSSeQctmSznfdNuRg

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00ae9aef11

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sandbox.rs Resolved
Comment thread src/sandbox.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1782065bc1

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sandbox.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 1782065bc1

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/sandbox.rs Resolved
@lydakis
lydakis merged commit 6cbd621 into main Oct 28, 2026
3 checks passed
lydakis pushed a commit that referenced this pull request Oct 28, 2026
…-only first

Codex's guardian sees only what would leave the sandbox and runs as a
read-only agent turn that may inspect before it answers. Now the daemon
sandboxes bots (#265), the approver does the same:

- The state gains `sandbox` (mode, writable folders, network) for a
  sandboxed bot, and the policy carries Codex's investigation and
  execution-environment sections: an escalation or a retry after a
  sandbox denial is not suspicious in itself, the justification is
  untrusted, and tools are called only when they would flip the outcome.
- Where a sandbox runs, a model judge's base has `shell` and `read` in a
  read-only sandbox (no writes, no network), and each round's fork starts
  in the bot's workspace. Elsewhere it has no tools, as before.
- A judge base from an older approver, its policy since changed, is
  remade instead of refused as a bot that is not a judge: a judge is
  known by its instructions' first sentence and its read-only tools.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NSAn6KdbZwnLbDoimEJpTZ
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.

2 participants