Skip to content

An automation gate an agent wrote runs in that agent's sandbox - #783

Merged
lydakis merged 12 commits into
mainfrom
claude/project-thread-0twv9e
Nov 7, 2026
Merged

lydakis merged 12 commits into
mainfrom
claude/project-thread-0twv9e

Conversation

@lydakis

@lydakis lydakis commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

What

Codex's review of #771 found that an automation's --if gate runs as the person, unsandboxed, so a gate like cd FOLDER && ! ./quiet runs whatever script an agent last wrote there with the person's full permissions. George picked the fix: a gate runs in the sandbox of the agent that wrote it, with that agent's own capped daemon socket, as Codex runs whatever an agent wrote. Gates the person or Sonny added still run as the person.

  • Daemon (protocol 54): lend. {"op":"lend","bot":NAME,"bot_id":ID?} answers {bot, bot_id, policy, env}. policy is the sandbox the daemon builds for the bot's commands, from the same bot_sandbox its turns call, so every --protect-path, --wall and the store stay kept; the bot's own capped socket listens while the asking session lasts. env is the command's whole environment: the daemon's own minus the credentials it holds and what --shell-exclude withholds, built by shell_environment, which the tool shell now shares. Only a session outside every sandbox may lend; a bot's own socket refuses it (not_permitted). A wrong bot_id is bot_not_found.
  • agent sandbox --bot NAME [--bot-id ID] [--store/--socket]. Lends, then runs the command in that policy with that environment in place of the caller's: the bot's env setting (so $SONNY_STATE), AGENT_BOT, AGENT_BOT_ID, and AGENT_SOCKET reaching the daemon through the bot's socket (a handed descriptor on Linux, as turns do). An unconfined bot's command runs unconfined, with the same environment. Exits as the command does, or 125 when it couldn't run it (usage, no sandbox, bot not found), as env and timeout do.
  • Sonny. An automation records who wrote its gate: an agent (--if-by NAME --if-by-id ID), set from the agent whose shell or automations tool added it, or the person (--if-by-person). A fire runs an agent's gate through agent sandbox --bot; the gate's agent gone means the check couldn't run (a failed fire, told once, as any broken gate is). The person's gates, and Sonny's own (the memory cleanup's, an ask's deadline's), run as the person. An ask's deadline goes through a new add_sonnys(name, at, gate, message) so its Sonny-written gate stays Sonny's. An automation added from a confined shell on macOS keeps the daemon's own socket, not the bot's (SOCKET.d/ID), which can't lend.
  • Gates from before this release do not run. Their definitions don't say who wrote them, and any could be an agent's, so none runs as the person any more: each check fails (told once to the agent; the automation sends nothing) until the automation is added again, which records its writer. The only exceptions are Sonny's own two, the memory cleanup's '~/.agent/memory' changed and an ask's deadline's 'SONNY' ask open 'BOT' TURN 'CALL', recognised by their whole text, so nothing appended to them passes. This is fail-closed, not a migration: the writer can't be recovered from an old definition.
  • Upgrade step agent-gates. Tells the lead its gated automations stopped checking and asks it to add each again with replace (or name to the person the ones they wrote). A lead re-adds its .next whenever it looks. Done once every gate runs.
  • Docs: RUST_PROTOTYPE (lend, agent sandbox --bot), SECURITY.md Triggers + Known limits, docs/SONNY.md --if, the automation skill (a monitor's gate now has $SONNY_STATE: cd "$SONNY_STATE"/jobs/NAME && ! ./quiet), FEATURES Automations row (the upgrade-step test needs it named there).

Goal checks are out of scope: /goal was removed wholesale in #782.

Performance

A person's gate costs what it did. An agent's gate adds one agent process, one lend round trip (the policy plus the daemon's environment, some tens of variables) and the sandbox launch per check. Nothing changes on the turn path: the tool shell's environment comes from the shared function with the same steps in the same order, and the service holds one more map, empty unless a gate runs. Local timings (docs/DAEMON_MEASUREMENTS.md, "An automation gate in its agent's sandbox"): the person's gate 1.4 ms, an unconfined agent's 4.7 ms, a read-only agent's 14.3 ms against 12.2 ms for bare agent sandbox, so the lend is about 2 ms over the sandbox's own launch. The Perf workflow's matched screen (head 3515a11) shows no change past noise on any daemon or Sonny measure (lone submit CPU 31.1 → 30.8 ms, CPU per turn 0.92 → 0.92 ms, idle RSS 15.2 → 15.3 MiB, quiet window 1.54 → 1.34 ms/s); recorded in the same section.

Tests

  • tests/test_cli.py: a command run as a workspace-write bot can't write a daemon --protect-path and sees neither a withheld daemon variable nor the caller's environment; a command run as a read-only bot sees its variables, reaches the daemon through its own socket, writes nothing, can't lend again from inside (125); an unconfined bot's runs unconfined; a wrong id or a missing bot runs nothing (125, bot_not_found).
  • tests/test_trigger.py: a real fire with an agent's gate runs it in that agent's sandbox (its $SONNY_STATE, no write), a gone identity fails the check with 125, the person's gate still writes as the person, and a gate with no recorded writer runs nowhere.
  • sonny/src/trigger.rs: a gate runs as its writer; one from before runs only when it is Sonny's own word for word (appended commands, another path to sonny, a non-numeric turn all fail); add_sonnys's arguments parse; a capability socket path resolves to the daemon's own; --if-by and --if-by-person round-trip through a definition; the same gate by another writer differs on if.
  • src/cli.rs: the new flags.

Local, after merging main (with #782's /goal removal; the only conflict was SECURITY.md): cargo fmt, cargo clippy --workspace --all-targets -D warnings, cargo test --workspace green; tests.test_trigger (release runtime, bubblewrap) passes.

Upgrade notes

  • Restart the daemon after upgrading (protocol 53 → 54); Sonny's gates call agent sandbox --bot, which needs a daemon that knows lend.
  • Every automation if added before 0.9.0, except Sonny's memory cleanup and ask deadlines, stops running: its checks fail and it sends nothing until it is added again. A lead re-adds its own .next when it next looks, which, with that check failing, is when the person next writes to it or the upgrade note reaches it (until then that lead isn't woken for what it holds). The agent-gates upgrade step asks the lead to re-add the rest and to name to the person any it can't (theirs, or ones its sandbox can't run); the person re-adds those with sonny automation add --replace.
  • A gate now runs no further than its agent's own commands reach, with the daemon's environment rather than the scheduler's: a monitor's quiet script that needs a folder or the network outside the lead's sandbox fails its check (told once) until the person widens the lead's sandbox or adds the automation themselves.

🤖 Generated with Claude Code

Codex's review of #771 found that a trigger's `--if` ran as the person, so
a gate such as `cd FOLDER && ! ./quiet` ran whatever script an agent had
last written there unsandboxed. A gate now runs where its writer's own
commands run, as Codex runs whatever an agent wrote.

- Daemon (protocol 54): `lend` answers a bot's record with its own capped
  socket, listening while the asking session lasts; a bot's own socket
  refuses it.
- `agent sandbox --bot NAME [--bot-id ID]` runs a command in that bot's
  sandbox, with its env setting and its socket; 125 when it could not run.
- Sonny records who wrote each gate (`--if-by`) and runs an agent's gate
  through `agent sandbox --bot`; the person's and Sonny's own run as before.
- Upgrade step `agent-gates` asks the lead to add its older gated
  automations again.

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

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T08:42:35.951064Z a4bed8f New commits
🔒 Security Review ✅ Completed 2026-11-07T06:44:29.855524Z 22f3b1f PR opened
ℹ️ 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: 22f3b1fc68

ℹ️ 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/main.rs Resolved
Comment thread src/main.rs Resolved
Comment thread sonny/src/trigger.rs Resolved
Every new gate's definition now names its writer: an agent
(`--if-by NAME --if-by-id ID`) or the person (`--if-by-person`). One with
neither was added before this release and could be an agent's, so it no
longer runs as the person: its check fails, told once to the agent, until
the automation is added again. Sonny's own two gates, the memory cleanup's
and an ask's deadline's, still run, recognised by their whole text.

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

@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: 02a32c41e5

ℹ️ 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 sonny/src/trigger.rs Resolved
Codex review of #783:
- `lend` answers the policy the daemon builds for the bot's commands, its
  protections and walls included, and their whole environment (the
  daemon's, without the credentials it holds or withholds), shared with
  the tool shell (`shell_environment`); `agent sandbox --bot` runs in them
  in place of its caller's.
- An ask's deadline names its fields to `add_sonnys` (an envelope had made
  every deadline fail to schedule).
- An automation keeps the daemon's own socket, not the bot's own a
  confined shell on macOS has (`SOCKET.d/ID`), which may not lend.

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

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

ℹ️ 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 sonny/src/trigger.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: eac55be130

ℹ️ 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/main.rs Resolved
A lent command's placeholders for missing protected folders were held in
the CLI's own list, apart from the daemon's: whichever side ended first
could remove one the other's sandbox still mounted, lifting it there.
The daemon now holds the lent policy as one of the bot's own commands
until the session closes, and agent sandbox --bot holds nothing itself.

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

# Conflicts:
#	sonny/FEATURES.md
#	sonny/src/trigger.rs
@lydakis
lydakis merged commit 243d326 into main Nov 7, 2026
5 checks passed
@lydakis
lydakis deleted the claude/project-thread-0twv9e branch November 7, 2026 09:13
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