Skip to content

Sandbox: sandboxed bots use the agent CLI through their own socket, capped by caller - #276

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

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

Conversation

@lydakis

@lydakis lydakis commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

#265 denied the daemon's socket to every sandboxed command, which also took the agent and sonny CLIs away from sandboxed bots. Those CLIs are how bots delegate, message each other and report back. This PR brings them back and limits each request to what the calling bot may do. It also closes the earlier finding that a confined command could answer its own approvals or reconfigure its gates.

What changes

  • A socket per sandboxed bot: each sandboxed bot gets its own socket at SOCKET.d/BOT_ID, beside the daemon's.
    • The daemon opens it the first time one of the bot's confined commands runs, and closes and removes it when the bot is deleted or expires. Every connection on it is a session that answers as that bot.
    • Linux: bwrap binds the bot's socket over the daemon's socket path, so agent finds it at the usual place. A read-only tmpfs hides the folder that holds the bots' sockets.
    • macOS: Seatbelt denies the daemon's socket and the bots' folder, and allows only the bot's own socket, with network on or off.
    • On both platforms:
      • AGENT_SOCKET names the socket the command should use.
      • The folder stays read-only in every root, so no bot can plant a listener in another bot's place or reach another bot's socket.
    • When there is no such socket (a daemon on stdio, or one whose socket path leaves no room for .d/ID), sandboxed commands get no way in, as before.
  • Caps on a bot's own socket. A request outside these gets not_permitted.
    • Refused: configure, answer, tool_result, serve_approvals, renew_approvals and shutdown.
    • create and fork:
      • The caller is always the creator, and naming another creator is refused, so the new bot inherits the caller's sandbox (Settings::under).
      • The new bot's workspace and writable folders, plus a fork's source's, must be folders the caller can write.
      • A fork with allow: [] only answers questions, so it may be of any bot.
    • Declared tools that a client answers: the caller may pass on only those it has itself, answered by the same client. This applies to a create that declares them and to a fork whose callable tools include them. Otherwise a bot could get a client to act on its behalf.
    • submit:
      • The message reads as the caller's: it comes from the caller's running turn, or else carries its name as origin. A from naming another bot is refused.
      • A workspace given to any sandboxed bot must be one the caller can write, because a turn's folder becomes the bot's.
    • delete, prune, compact and interrupt: only on the caller itself or a bot it made.
    • Everything else works as on the daemon's socket: reads, wait, follow, the approvals listing and models.
  • Roots reached through a link: a sandbox root that a link was swapped in for since is refused (sandbox_unavailable). A bot may write the folder above a folder it gave a child, so following that link would carry the child's sandbox elsewhere. Each confined call builds its policy anew, off the runtime thread, so the swap is caught on the next call.
  • Store: inspect_id.

Known gaps, declined here:

Performance

A matched screen against main is recorded in docs/DAEMON_MEASUREMENTS.md under "Sandboxed bots' own sockets". Every measure's range overlaps between the two builds. Each request adds one hash lookup. The rest of the new work runs only on a bot's own socket, or on a sandboxed bot's confined call.

Tests

  • Runtime (real daemon over a socket, real bwrap): a sandboxed bot's shell talks to $AGENT_SOCKET. The test checks that:
    • Listing bots works.
    • configure, answer and shutdown are refused.
    • A child inside the bot's folder is made as its own, with workspace-write.
    • These are refused: a child outside the folder, one claimed for another bot, one given a client-answered tool, a fork of a bot with such a tool, and the bot's own turn queued with an outside folder.
    • Deleting another bot is refused, and deleting its own child works.
    • Forking an outside bot is refused, and an allow: [] fork works.
    • Writing into the sockets' folder fails, and so does connecting to another sandboxed bot's socket.
    • Deleting a bot removes its socket.
    • On Linux, AGENT_SOCKET is the daemon's path.
  • Tool contract:
    • With the bot's own socket set, a connect to the daemon's path reaches it, network on and off.
    • A root swapped for a link is refused.
  • Unit:
    • bwrap binds the bot's socket and hides the folder.
    • Seatbelt denies the folder before allowing the bot's own socket.
    • reach() picks the right path per platform.
  • Locally:
    • cargo test --workspace with AGENT_TEST_SANDBOX=1 passes.
    • The full runtime suite (tests.run --jobs 4, all 42 modules) passes.
    • Clippy and fmt pass.

macOS isn't run here. The Seatbelt rules follow the existing socket deny, and a check on a Mac is still to do.

🤖 Generated with Claude Code

claude added 11 commits October 28, 2026 03:11
…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
…-6zwinw

# Conflicts:
#	docs/DAEMON_MEASUREMENTS.md
…apped to what it may do

Each sandboxed bot gets a socket of its own beside the daemon's, bound over
the daemon's path in bwrap and allowed by Seatbelt, and named by AGENT_SOCKET,
so the agent CLI works in its shell. Requests on it answer as that bot: no
configure, answers, tool results, serving approvals or shutdown; what it makes
is its own and inherits its sandbox inside its folders; it removes only its
own bots; what it sends reads as its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSSeQctmSznfdNuRg
…to claude/project-thread-6zwinw

# Conflicts:
#	docs/RUST_PROTOTYPE.md
#	src/sandbox.rs
#	src/server/mod.rs
#	src/server/turn.rs
#	src/tools.rs
#	tests/test_approvals.py
#	tests/tool_contract.rs
@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-28T06:50:08.979712Z b5cae03 New commits
🔒 Security Review ✅ Completed 2026-10-28T06:53:22.135670Z b5cae03 New commits

Security findings

Advisory findings (2)

ℹ️ 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 Security Review · Automatically triggered

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

Reviewed commit: 3ad1ecaa54

ℹ️ 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/server/mod.rs Resolved
The test's own socket sat beside the daemon's, so hiding the folder of
bots' sockets hid the daemon's path too; the daemon keeps them in
SOCKET.d/.

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: bfe1141b7d

ℹ️ 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/server/mod.rs Resolved
Comment thread src/server/mod.rs Resolved
Comment thread src/server/socket.rs Resolved
A folder a bot was given can sit in one its creator may write, and the
creator can swap a link in for it later; bound by its path, bubblewrap
would follow that link. Each root is now opened folder by folder without
following links, refused if one was swapped in, and bound from that
descriptor.

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: 4b0e9bbff0

ℹ️ 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
…lose a bot's socket with it

A fork keeps its source's declared tools, so forking a bot whose tools a
client answers is held to what the caller may pass on, as create is. A
turn's folder becomes the bot's, so one given to any sandboxed bot must
be the caller's to write. A deleted or expired bot's own socket is
closed and removed.

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

lydakis commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

@codex review


Generated by Claude Code

@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: fbd8aaada7

ℹ️ 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/server/socket.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: fbd8aaada7

ℹ️ 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/server/mod.rs Resolved
… sockets off the runtime thread

Pinned descriptors outlived bubblewrap into the command itself, which
could reach the host's folders through them. Each confined call builds
its policy anew, off the runtime thread, so a root that a link was
swapped in for since is refused there instead. Closing a deleted bot's
own socket takes a lock and unlinks a file, so it runs on a blocking
worker.

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

# Conflicts:
#	docs/DAEMON_MEASUREMENTS.md
…-6zwinw

# Conflicts:
#	docs/DAEMON_MEASUREMENTS.md

@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: c58f65baf4

ℹ️ 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/server/mod.rs Resolved
Comment thread src/server/mod.rs Resolved
…rred attribution stable across retries

A caller whose allowed list leaves out a client-answered tool can't
declare it for a bot it makes, nor have a new bot inherit it. A submit on
a bot's own socket without from is named by the caller's name as origin,
never by whatever turn it runs then, so a retry is the same request.

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

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

lydakis commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

@codex review
@codex security review


Generated by Claude Code

@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: 9e834d947b

ℹ️ 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/server/mod.rs Resolved
Comment thread src/server/mod.rs Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 9e834d947b

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ 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.

@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: 7c679356ed

ℹ️ 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/server/mod.rs Resolved
…-6zwinw

# Conflicts:
#	docs/DAEMON_MEASUREMENTS.md
The store answers a resent fork before it looks up the source, so a
client recovering a lost response still gets the fork it made.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSSeQctmSznfdNuRg
@lydakis
lydakis merged commit 5b927c9 into main Oct 28, 2026
3 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.

2 participants