Skip to content

Run Sonny's git in a sandbox where an agent may have written the repository - #603

Merged
lydakis merged 21 commits into
mainfrom
claude/project-thread-hue6af
Nov 1, 2026
Merged

lydakis merged 21 commits into
mainfrom
claude/project-thread-hue6af

Conversation

@lydakis

@lydakis lydakis commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Fixes #597. Also fixes the two code findings from #607's review of #529 (scheduler, backup), listed at the end.

The hole

Git runs a repository's hooks and the programs its config names, even just to list its files. I checked this on git 2.43: status and ls-files run core.fsmonitor, while rev-parse and branch --show-current don't.

A sandboxed agent can git init a repository inside its folder and write those hooks and settings. Sonny then ran git there as the person in three places:

  • File tree. git status runs when you view the folder, with no approval at all.
  • Seed. ls-files runs when a task's worktree is seeded.
  • start_task with folder. It runs git worktree add, which fires the post-checkout hook, fsmonitor and filters.

The fix (George picked this on 11-01: run Sonny's git in the sandbox)

  • New command: agent sandbox [--writable PATH]... -- COMMAND. It runs one command in the sandbox a bot's commands run in, with no daemon, like Codex's codex sandbox.
    • With no --writable, the command is read-only.
    • It keeps what a daemon keeps read-only: the agent's home (even when that home doesn't exist yet), plus .git, .agents and .codex at the top of each root.
    • It holds the sandbox's placeholders while the command runs and clears them before it exits.
    • The network is always off, so the command reaches no Unix socket, the daemon's included (seccomp on Linux, Seatbelt on macOS). With no daemon, nothing could hide that socket by name. The Codex security review flagged this while a --network flag existed, so that flag is gone.
    • There is no protocol change. The daemon crate only gains Hold::release.
  • Sonny routes those git calls through it (task::confined):
    • The tree's status and the seed's two listings run read-only, with --no-optional-locks.

    • A task's worktree is made in two steps.

      1. Sonny runs worktree add --no-checkout -b itself. Git runs none of the repository's code here: no checkout, no hooks, no fsmonitor.
      2. The worktree is checked out (checkout -f) in the sandbox. The sandbox can write only the worktree, its own git folder, and any .agents/.codex folders the commit tracks. The network is off.

      The checkout is what runs filters and the post-checkout hook. The shared git folder is never written from the sandbox, so a config with an include or with per-worktree config still works.

    • A start whose branch agent/NAME was kept from an earlier task now fails before git runs. Before, the undo deleted that kept branch.

    • Before a removal without discard, git's own checks run in the sandbox, since --force skips them:

      • status with --ignore-submodules=none;
      • the refusal to remove a worktree that holds submodules, because their repositories would go with it. Submodule names are read as bytes.

      Removal then uses worktree remove --force. The branch is deleted with no hooks.

  • Fallback. On a machine with no sandbox (no bubblewrap), no agent is confined either, so git runs directly as before. Sonny decides this once, by having the sandbox run git --version.

Also: #607's code findings for #529

  • Scheduler started after its HOME was deleted. It used to recreate HOME when it opened its doorbell and then run on idle. It now checks for this before making anything, and lets go of its system job.
  • Backup clone made by hand. Setup used to count ~/agent-home as set up as soon as it had a remote. It now also needs setup's first sync, so setup still restores the clone.

Trade-off

A repository's own hooks and filters now run confined when Sonny checks out a task worktree. A legitimate post-checkout that writes outside the worktree, or a filter that needs the network (an LFS smudge for an object the repository doesn't hold), makes the start fail with git's message and leaves nothing behind. Git behaves the same way when an agent runs it in its own sandbox, and Codex confines git the same way.

Tests

  • Sandbox unit test what_an_agent_left_in_a_repository_runs_only_in_the_sandbox. It checks that:
    • fsmonitor fires under plain git but not when confined;
    • a post-checkout hook runs but can't write outside the sandbox, even when the config has an include;
    • a tracked .agents/AGENTS.md is checked out.
  • Other new tests:
    • a_submodule_is_found_whatever_bytes_its_name_has
    • a_task_s_worktree_with_a_submodule_is_removed_only_with_discard
    • a_task_named_for_a_kept_branch_does_not_start_or_delete_it
    • a_scheduler_started_for_a_home_already_gone_makes_it_no_more
    • a_clone_made_by_hand_is_not_set_up_until_setup_syncs_it
    • the CLI test for sandbox
  • By hand:
    • socket(AF_UNIX) fails with EPERM inside the sandbox;
    • .git/hooks and .codex can't be written;
    • a missing ~/.agent can't be made;
    • a commondir the command makes is removed afterwards.
  • Suites: cargo test -p sonny passes, the CLI tests pass, and clippy is clean with -D warnings.

Docs: a docs/RUST_PROTOTYPE.md Sandbox paragraph, and the sonny/FEATURES.md Tasks, tree, triggers and backup rows.

🤖 Generated with Claude Code

claude added 16 commits November 1, 2026 07:06
The eval answered every ask with allow, and the sandbox asks exactly
before a write outside the run, so a fake HOME did not keep agents out of
the real one: an S1 backup landed in the owner's ~/Backups. The ACP
client and allow_waiting now deny a call that names a path in the real
home outside the run's root, and allow the rest as before (escalations
with no path, system paths, anything in the run). After each run, what
changed in the real home a few levels down (past hidden folders and
Library) goes to outside.txt and is said on stderr.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
A command's write targets can't be read from its words, so the check now
denies what could reach the real home rather than only literal paths in
it: a folder above it (cd /Users && mkdir me/x), a `..` that climbs out
of the run from its shallowest folder, a `~name`, and a call listed cut
(task asks whose arguments were bounded) or one Sonny offered only to deny.

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

Scanning a command's words can't stop a path built at run time (a Python
call reading the real home from the user database), so the path check was
a mitigation, not isolation. Runs now use an `eval` permissions row: the
sandbox writes the agents' folders plus the run's backups and origin, the
network (and with it every Unix socket) is off, and every call that would
leave the sandbox comes to the eval, which allows only one plain call of
~/.agent/trigger or ~/.agent/memory (no operators, expansions or line
breaks) and denies the rest, logging each answer. outside.txt stays as the
after-run check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
An approved `~/.agent/trigger add --if CMD` ran CMD in the scheduler,
outside every sandbox. The eval now allows each script's verbs with only
the flags that run nothing else: no `--if`, no `--start`, no
`memory schedule` or `cleanup`.

Runs lived under /tmp/role, which every sandbox writes, so an agent could
replace the run's copy of the build, its sources' script, or another run.
They now live under ~/.role-eval.

Refs #521

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
The eval row's reviewer is the person, so a task's call parks until the
eval answers it. Only settling answered them, after the lead's prompt
returned, so a lead waiting on a task before answering waited out the
prompt. Acp.ask now serves them every few seconds while a request is out.

Refs #521

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
shlex read `{watch,--if,'cmd'}` as one name, but Bash expands it into
`--if cmd`. The allowlist now tokenizes the command itself and refuses
anything Bash would expand, substitute or redirect: outside quotes a word
holds only letters, digits and `_./:,@%+-`; double quotes refuse `$`, a
backtick, a backslash and `!`.

Refs #521

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
The eval row extends `ask`, so start_task, subscriptions and triggers wait
on the eval, which denied every call but a shell one: the lead could not
delegate or subscribe, and the scores would have measured the harness. The
eval now allows a task started in the lead's folder (its setup is the
lead's read-only .agents/setup), a removal, a subscription and a trigger
without `if` or `start`; new projects, panes, scripts, goals and the
browser stay denied.

Refs #521

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
Sonny runs `git worktree add` outside the sandbox in the folder's
repository, and a repository an agent made inside the lead's has hooks,
config and filters the agent wrote. The day needs no folder, so a start
naming one is denied (#597 tracks it in Sonny).

Refs #521

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

Git runs a repository's hooks and the programs its config names (an
fsmonitor, a filter) even to list its files. A sandboxed agent can make a
repository inside its folder and write those, and Sonny ran git there as
the person: the file tree's status on viewing the folder, the seed's
listing, and start_task's `git worktree add` with `folder`.

`agent sandbox [--writable PATH]... [--network] -- COMMAND` runs one
command in the sandbox a bot's commands run in, with no daemon, as Codex's
`codex sandbox`. Sonny now runs those git calls through it: the tree's
status and the seed's listings read-only, a task's worktree writing only
the repository's git folder and the new worktree, with the lead's network,
and a task's change check read-only before its worktree is removed with
`--force` and its branch deleted with no hook. On a machine with no
sandbox, where no agent is confined either, git runs as before.

Fixes #597

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
With the network on, a sandbox reaches every Unix socket but those the
daemon names, and agent sandbox has no daemon to name its own, so a hook
could reach the daemon and run anything through it (Codex security review
on #603). The sandbox now always runs off the network, where it can make
no Unix socket at all (seccomp on Linux, Seatbelt on macOS). Sonny's
worktree git loses only the network an LFS smudge would fetch with.

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

Removing a worktree with --force skipped git's own refusal to remove one
holding submodules, whose repositories go with it, and its status check,
which counts submodule work whatever submodule.NAME.ignore says. Both
now run in the sandbox before removal (Codex review on #603).

A start whose branch agent/NAME was kept from an earlier task now fails
before git runs, rather than deleting that branch while undoing a
worktree add that could never have made it.

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

The sandbox keeps a git folder read-only whole when its config includes
other files or turns on per-worktree config, so a confined worktree add
could not make its branch there (Codex review on #603). Sonny now makes
the worktree with git running none of the repository's code (no
checkout, hook or fsmonitor), then checks it out in the sandbox writing
only the worktree and its own git folder. The checkout is what runs
filters and the post-checkout hook; the shared git folder is never
written from the sandbox.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
…exit; submodule names as bytes

agent sandbox ran its command without the hold a bot's command takes, so
on Linux a commondir the command made, and the mount placeholders, stayed
after it (Codex review on #603). It now holds them while the command
runs and lets go on its own thread before exiting (Hold::release), since
a drop's thread would end with the process.

The submodule guard read index names as UTF-8 and skipped others; it now
reads their bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
A daemon the CLI starts keeps .git, .agents and .codex (and an existing
.aws) read-only at the top of every writable root; agent sandbox took
none, so a command could leave hooks or agent settings in a checkout it
was given (Codex review on #603). It now takes the same lists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
macOS refuses the name with EILSEQ, so such a submodule can't be checked
out there to lose; the test checks the case where it can.

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

lydakis commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

The macos job on 6447c0f failed in sky::tests::a_crowd_folds_to_clouds_and_keeps_who_needs_you. This PR doesn't touch sonny/src/sky.rs or anything it draws. The same test passed in the macos job on 0b12864, which had the sky code unchanged, and it passes here on three local runs. I can't re-run the job from this session.

Since then, main gained #601, a sky change. I merged main in (no conflicts; the Sonny tests and clippy pass), and that push starts a fresh CI run. If the sky test fails there again, I'll look into it as a real bug in that test.


Generated by Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 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-11-01T11:00:52.268490Z 417c634 New commits
🔒 Security Review ✅ Completed 2026-11-01T08:27:01.177356Z dc69406 PR opened

Security findings

Advisory findings (1)

ℹ️ 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: 90269dbe9c

ℹ️ 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/task.rs Resolved
Comment thread src/main.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: dc69406cce

ℹ️ 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/main.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: dc69406cce

ℹ️ 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/task.rs Resolved
Comment thread src/main.rs Resolved
Comment thread sonny/src/task.rs Resolved
…e protected

A sandbox keeps .agents and .codex read-only at its top, so a worktree
of a repository that tracks them could not be checked out; the confined
checkout now writes those the commit holds, as any tracked file (a hook
or filter could already write those). And agent sandbox dropped the
agent home's protection when it was not there yet, since it could not
canonicalize it; it now keeps it by its parent's real path, so it can't
be made. (Codex review on #603.)

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

@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: 056af67054

ℹ️ 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/task.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: 06b5aef837

ℹ️ 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/task.rs Resolved
Comment thread src/main.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: bb464c5d82

ℹ️ 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
…p clone is not set up

A scheduler the system started after its HOME was deleted made HOME
again opening its doorbell, so never saw it gone and ran on idle; it now
checks before making anything. And backup counted as set up once
~/agent-home had a remote, though a clone made by hand has had no
restore or first sync and the scheduler never syncs it; setup now needs
that first sync too. (Codex code review on review-only #607, for #529.)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
@lydakis
lydakis merged commit d9d647e into main Nov 1, 2026
10 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.

start_task in a nested repository runs that repository's hooks and config outside the sandbox

2 participants