Skip to content

feat(pi): run Pi shell and file tools inside srt - #228

Merged
furedea merged 29 commits into
mainfrom
feat/sandbox-pi-shell-with-srt
Nov 12, 2026
Merged

furedea merged 29 commits into
mainfrom
feat/sandbox-pi-shell-with-srt

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #221

概要

Pi の bash と,ファイルを触るツール (read / write / edit / grep / find / ls) を,同じ生成済み srt 設定の下で実行する.許可はコード上のパス判定ではなく,カーネル (Seatbelt) が allowWrite / denyWrite / denyRead で決める.

  • bash: bash_sandbox.ts が bash ツールを置き換え,全コマンドを srt --settings <settings.json> -c <command> で実行する.
  • ファイルツール: Pi の tool operations から,srt 内で動く小さな helper (file_operations.mjs) を呼ぶ.helper は信頼しない配管で,バグがあってもアクセスは広がらない.helper が無い,または設定が不正な場合は実行を拒否する.
  • 設定生成: Claude の sandbox ブロックと同じ設定元から生成し,~/.pi/agent/auth.json を denyRead に加える.実行時に worktree と git common dir を allowWrite に追加し,.git の hooks・config・pointer 類,ネストした .git,project の .pi を denyWrite にする.必須キーを全て出力し,検証に失敗したら実行しない.
  • hook_bridge: worktree のパス文字列チェックと,ファイルツールの fail-closed を削除した.hook は Claude と同様に,失敗時は呼び出しを通す policy 層に戻る.
  • テスト: 登録されている全ツールを列挙し,ファイルに触るツールが helper を経由しなければ失敗する.拡張や MCP のファイルツールは許可しない.ADR 0029 を追加.

検証

  • cargo fmt --check / cargo clippy -- -D warnings / cargo test / npm test (fake srt) が成功.
  • 実 srt 0.0.52 (macOS) で,worktree 外のファイルへのハードリンク作成 (ln <outside> <worktree>/x) が Operation not permitted で拒否されることを確認した.通常の書き込みは成功する対照も確認済み.追加の deny は不要.Linux (bwrap) では未確認.
  • Linux (bwrap) は未検証.denyGlobRegex を持つ srt が必要 (nixpkgs 0.0.52 は不可).srt の導入は dotfiles 側のフォローアップ.

🤖 Generated with Claude Code

furedea and others added 2 commits November 12, 2026 01:39
Replace Pi's bash tool with an extension that wraps every command in
srt, using a policy generated from the Claude sandbox source plus the
runtime worktree and common git dir. Refuse to run when the policy is
invalid.

Refs #221

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Block read/write/edit targets outside the worktree or inside .git, and
block file-tool calls when the hook times out, crashes or fails to spawn.
bash keeps its existing behavior.

Closes #221

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-12T03:58:58.120126Z 3289d73 Manual request
ℹ️ 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.

Comment thread src/generation/assets/pi/hook_bridge.ts Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Review summary

No blocking findings (0 × P0/P1). Two P2 findings are posted inline:

  • P2 hook_bridge.ts: the PR removes the missing-adapter guard. If the adapter is absent, python3 exits with code 2, which the bridge reads as a deny. That blocks every tool call, not just file tools, and swallows all user input events.
  • P2 bash_sandbox.ts: git rev-parse fails when Pi starts outside a git repo, which disables the bash tool for the whole session. Neither the README nor the tests cover this.

The rest looks sound: the srt command quoting, the policy validation, the fail-closed behaviour on bad settings or a missing srt, and the symlink and .git handling in the file-tool boundary. Test coverage is good apart from the two gaps above. As the PR description says, nothing has been checked against a real srt yet.

🤖 Generated with 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: deaefb8c61

ℹ️ 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/generation/assets/pi/hook_bridge.ts Resolved
…ively

Normalize a leading @, unicode spaces and ~ before the worktree check, and
reject .git variants (case, trailing dots/spaces, git~1).

Refs #221

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread src/generation/assets/pi/hook_bridge.ts Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Review summary

I posted 3 inline findings. 1 of them blocks the merge.

  • P1 bash_sandbox.ts: in a linked worktree, the .git gitfile sits inside allowWrite and is not in denyWrite. Sandboxed bash can point it at an attacker-controlled gitdir (for example one whose config sets core.fsmonitor), and the next git command that runs outside the sandbox (Pi hooks, the user's shell) executes it. Submodule hooks and config under common/modules/* are also writable.
  • P2 bash_sandbox.ts: when Pi starts outside a Git repo, git rev-parse fails, and that disables the bash tool entirely.
  • P2 hook_bridge.ts: removing the existsSync(ADAPTER) guard means a missing adapter makes python exit with code 2. That is read as deny, so bash calls are blocked and user prompts are dropped, not just file tools.

The file-tool path checks themselves (symlink resolution, dangling links, .git variants) look solid and have good tests. Note that end-to-end verification against a real srt is still pending, as the PR description says.

🤖 Generated with 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: 03f071b587

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

- bash: build the srt policy per call cwd, skip Git entries outside a
  repository, and deny writes to a linked worktree's .git pointer file
- hook bridge: a missing adapter no longer blocks bash or prompts; file
  tools still fail closed
- file tools: ignore format characters, stream suffixes and 8.3 aliases
  when matching .git
- nix: provide git to the check phase

Refs #221

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea-agent

furedea-agent Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

レビュー指摘への対応 (4377d36):

  • 非 git ディレクトリで bash が使えない: git 固有のエントリを省略して実行するようにした.
  • linked worktree の .git gitfile: denyWrite に追加した.
  • 呼び出しごとの cwd: ポリシーを呼び出し cwd ごとに生成するようにした.
  • adapter 欠如で bash/入力まで拒否: file ツールのみ fail-closed,それ以外は従来どおりに戻した.
  • .git 判定: 大文字小文字,format 文字,: 以降,8.3 別名を無視して判定する.
  • nix-check: check phase に git を追加した.
  • srt の存在確認 (verify): srt の導入は dotfiles 側のフォローアップで,runtime_commands はソース側のマニフェストの責務.README に明記した.srt 不在時は bash が fail-closed で拒否される.
  • write/edit の TOCTOU (検査後の symlink 差し替え): hook 方式の既知の限界.ツール自体を置き換えない限り解消できないため,本 PR では対象外とし,bash は srt が境界を担う.

🤖 Generated with Claude Code

@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Review summary (read-only)

Found 1 blocking problem:

  • P1 bash_sandbox.ts: the common git dir is writable inside srt, but its commondir files (<common>/commondir and <common>/worktrees/*/commondir) are not denied. Sandboxed bash can rewrite one to point git at an attacker-controlled config with core.fsmonitor or core.hooksPath. The next git command run outside the sandbox (Pi hooks or the user) then executes the attacker's code. This gets around the hooks/config/gitfile protections. Details are in the inline comment.

Other things I checked and found no problem with:

  • merge_sandbox always creates sandbox.filesystem, so pi_sandbox::write_policy cannot fail on a source that has no sandbox block.
  • The rendered golden policy replaces the {} placeholder asset.
  • File-tool path normalization, the .git checks and the fail-closed paths (missing adapter, timeout, signal) are covered by the smoke tests.
  • Bash and prompt behavior stays the same when the adapter is missing.

🤖 Generated with 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: 4377d36ff7

ℹ️ 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 tests/pi_bridge_smoke.mjs Resolved
…via node

- rebuild the policy on every bash call so repository changes are seen
- deny writes to cwd/.git unless it is a real directory
- make the fake srt in tests independent of /usr/bin/env (nix sandbox)

Refs #221

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Review summary

1 blocking finding (P1) — see inline comment on bash_sandbox.ts:109.

  • P1: Sandboxed commands can write the whole git common dir. Only hooks, config and worktrees/*/config.worktree are blocked. They can still rewrite worktrees/<name>/commondir/gitdir, submodule modules/*/config/hooks, and the root config.worktree. Git that runs outside the sandbox (Pi, agent-harness hooks) then reads attacker config such as core.fsmonitor/core.hooksPath and runs code with no sandbox. Please block these paths, or allow only objects/refs/logs/index/HEAD, and add smoke-test cases.

Not flagged:

  • Pi's read tool may read outside the worktree. The README says this is intended.
  • Read/write/edit are now blocked when the hook adapter is missing. This matches the fail-closed design.

Also: the PR says it was not tested against a real srt, so whether srt applies denyWrite globs such as worktrees/*/config.worktree as expected is still unchecked.

@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: 5e5a154362

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

@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Review summary (read-only):

  • P1, bash_sandbox.ts:108: sandboxed bash can still write Git metadata that Git running outside the sandbox trusts. That is worktrees/*/commondir, worktrees/*/gitdir and modules/**/{config,hooks}. Rewriting commondir to point at a fake git dir inside the writable worktree, with core.fsmonitor set, would run code the next time git status runs outside the sandbox. Only hooks, config and config.worktree are denied today.

No other blocking issues found. The file-tool boundary, the fail-closed hook handling and policy validation look consistent with the PR description. As the description notes, nothing has been tested against a real srt yet.

🤖 Generated with Claude Code

@furedea

furedea commented Nov 12, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Review summary

1 blocking finding (P1)

  • P1 file_operations.mjs: the helper reads stdin by appending raw Buffer chunks to a string. When a multi-byte UTF-8 character is split across two pipe chunks (about 64 KiB each), it turns into U+FFFD. write and edit then write that damaged content to disk with no error. The same pattern on the parent side (bash_sandbox.ts, output += chunk) can damage grep, find and ls output. Fix by setting the stream encoding to utf8, or by concatenating the Buffers and decoding once. No test sends a large multi-byte payload.

I didn't find any other blocking problems. The policy generation, its validation, the .git and .pi deny rules, and the hook_bridge changes look consistent with the ADR.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to set up container
ℹ️ 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".

furedea and others added 2 commits November 12, 2026 12:33
…ubmodule git files

Also read the Pi policy source from the parsed Claude settings.

Refs #221

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 12, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread src/generation/pi_sandbox.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Review summary (read-only)

Checked the new bash_sandbox.ts / file_operations.mjs srt routing, policy generation (pi_sandbox.rs), the git common-dir / .git / .pi deny rules, the hook_bridge changes, and the tests.

No P0/P1 findings. The design fails closed: missing srt, an invalid policy, a tampered settings file or a changed git layout all refuse to run, and any tool other than the managed built-ins is blocked.

  • P2 (src/generation/pi_sandbox.rs): the Pi policy drops Claude's enableWeakerNetworkIsolation and excludedCommands. With github.agentToken enabled, gh / git push probably fail inside srt on macOS under Pi, while the same setup works in Claude.

Blocking findings: 0

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 217cacf65c

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

@furedea

furedea commented Nov 12, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread src/generation/pi_sandbox.rs Resolved
Comment thread package.json Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Review summary

I read the change without running it. 1 blocking finding (P1), 1 minor (P2).

  • P1 src/generation/pi_sandbox.rs:15: every generated Pi policy allows /nix/var/nix/daemon-socket/socket, and Claude's policy doesn't. Through nix-daemon, a sandboxed command can start builds outside srt. Fixed-output builds have network access, so this gets around the domain allowlist. For users in trusted-users, the daemon access is effectively root.
  • P2 package.json:10: nothing runs tests/pi_tools_conformance.mjs (not npm test, the Rust tests, or any workflow). So the check that every file-touching tool goes through the helper isn't enforced.

Checked and found no problem:

  • Install order: bridge assets are written before rendering, so the {} placeholder policy is always replaced.
  • Settings files: they sit in a temp directory covered by denyWrite, and a changed file is detected.
  • Git paths: the checkout's .git and nested .git are covered by denyWrite, as are the hooks, config and pointer files in the common git dir.
  • Tools: tools outside the managed set are blocked in tool_call.
  • Failures: a missing helper or invalid policy stops the tool from running.
  • hook_bridge.ts: a missing adapter now lets the call proceed, which matches what the PR says it intends.

🤖 Generated with 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: a48c049609

ℹ️ 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/generation/pi_sandbox.rs Resolved
@furedea

furedea commented Nov 12, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Review summary

Blocking findings (P0/P1): none. One P2, posted inline.

  • P2 bash_sandbox.ts: the nested .git, submodule and linked-worktree hook/config protections are written as globs. They only work if the installed srt supports denyGlobRegex, and nothing checks for that at runtime. Older srt on Linux (bwrap) may skip glob patterns, which would let a sandboxed command plant git hooks or config that git later runs outside the sandbox. Suggest failing closed when srt can't enforce globs.

What I checked and found no problems in:

  • The helper fails closed when it's missing, the policy is invalid, or the settings file is tampered with. .git, gitfile pointers and .pi are denied as intended, and the git layout is pinned for each cwd.
  • The Rust policy generation matches the golden output, and merge_sandbox always creates sandbox.filesystem.
  • Moving the missing-adapter check in hook_bridge into dispatch, and adding the stdin error handler, look correct.

Note: tests/pi_tools_conformance.mjs needs a local Pi install and isn't part of npm test or cargo test, so CI doesn't run it.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 3289d73c20

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

@furedea
furedea merged commit 37de3ac into main Nov 12, 2026
21 checks passed
@furedea
furedea deleted the feat/sandbox-pi-shell-with-srt branch November 12, 2026 04:15
furedea added a commit to furedea/dotfiles that referenced this pull request Nov 12, 2026
agent-harness を `37de3ac` に更新し,furedea/agent-harness#228(Pi の bash
とファイル系ツールを srt 内で実行)を Pi に配る.srt 本体は #455 で導入済み.

| 項目 | 現在 | 変更後 |
| --- | --- | --- |
| agent-harness | `e010600`(#228 を含まない) | `37de3ac` |
| `~/.pi/agent/extensions` | `hook_bridge.ts` のみ |
`bash_sandbox.ts`・`sandbox/file_operations.mjs`・`sandbox_policy.json`
が加わる |

## 検証

- [x] `nix build .#darwinConfigurations.mba.system` が成功
- [x] 生成物に Pi の拡張と `sandbox_policy.json` が含まれ,`denyRead` に
`~/.pi/agent/auth.json`,`network.deniedDomains` が出力されている

<details><summary>範囲外</summary>

- Pi の実機確認(ChatGPT プランが使えるようになってから)

</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
furedea pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.9.13](agent-harness-v0.9.12...agent-harness-v0.9.13)
(2026-11-12)


### Features

* **codex:** apply the secret path policy to the guarded filesystem
([#233](#233))
([0830fd9](0830fd9))
* **pi:** run Pi shell and file tools inside srt
([#228](#228))
([37de3ac](37de3ac))


### Bug Fixes

* dedupe the Nix socket in Pi's srt policy and name the failed sidecar
write ([#237](#237))
([1ccafe0](1ccafe0))
* fail on missing HOME, bound GitHub API waits, reject unknown hook keys
([#218](#218))
([c0b936d](c0b936d))
* **install:** publish atomically and keep Claude settings keys the
harness does not own
([#219](#219))
([c914c76](c914c76))
* **pi:** confirm ask decisions and deliver skills, instructions, and
settings ([#223](#223))
([2e755af](2e755af))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
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.

Sandbox Pi shell commands with srt and confine Pi file tools to the worktree

1 participant