Skip to content

feat(hooks): ask only for effects that escape the sandbox - #163

Merged
furedea merged 2 commits into
mainfrom
feat/ask-only-for-effects-outside-the-sandbox
Oct 15, 2026
Merged

furedea merged 2 commits into
mainfrom
feat/ask-only-for-effects-outside-the-sandbox

Conversation

@furedea

@furedea furedea commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Summary

Makes the OS sandbox the safety boundary for ordinary commands and asks only for effects that escape it or cannot be undone. Audit evidence from one afternoon after #159: 94 hook escalations, 82 of them "syntax" (a glob, $VAR, $(...), or heredoc anywhere in the call), the rest grep/rg/cat arguments that merely contained \ or $ inside quotes; script execution prompted on every call.

  • Run-time words are reported, not refused. The shell inspection now marks a glob or a parameter other than $HOME as dynamic and keeps its source text instead of raising. Command, process, and arithmetic substitution, heredocs, and dollar-quoted strings are still refused.
  • Read-only programs are judged structurally. rg, grep, cat, ls, find, jq, and the other programs listed in allowed_commands.json may take any literal, glob, or variable argument as long as no redirection writes a file (/dev/null and fd duplication are fine). rg -n "def \w+" agents, rg foo *.py, and cat $FILE are allowed; rg foo > out.txt still asks.
  • Any other program with a run-time argument asks, including git push $FLAGS, cd $DIR, and a dynamic program name. A literal deny prefix such as rm -rf $DIR still denies, and the forbidden hook no longer escalates; escalation is the allowed hook's job.
  • Sandbox-contained execution and edits move from ask to allow: python3, python, node, uv run python, uv run --frozen python (scripts, -c/-e, and a short module list), sed -i, perl -i, tee, truncate. python -m pip is denied like pip. uvx, npx, pnpm dlx, bunx, dependency changes, rm, merges, publishing, and the sandbox escape still ask.
  • Trivial builtins (echo, printf, pwd, date, true, false, test, basename, dirname, realpath, readlink, seq) are allowed so they no longer reach the classifier.
  • A cd or git -C to a run-time directory asks in the verification scope check instead of resolving a literal $DIR path.
  • ADR-0034 records the decision and supersedes ADR-0031; the README paragraph is updated.

Closes #162

Verification

  • uv run --frozen pytest tests/agents: 1492 passed.
  • uv run --frozen ruff check, ruff format --check, and ty check are clean; lefthook pre-commit and commitlint passed on both commits.
  • The Codex execpolicy rows for uv run python and sed -i now expect allow; uvx and npx rows expect prompt.
  • Live check after home-manager switch: run rg -n "def \w+" agents and python3 -c 'print(1)' in a new session and confirm neither prompts; run rg foo > out.txt and confirm it asks.

🤖 Generated with Claude Code

furedea and others added 2 commits October 15, 2026 15:49
Read-only programs take any argument, globs included, unless a redirection writes a file.

Other programs with a run-time argument ask; a literal deny prefix such as rm -rf still denies.

Script execution, in-place edits, and trivial builtins move from ask to allow inside the sandbox.

Fetched packages, dependency changes, rm, merges, and publishing still ask.

Running pip through python -m is denied like pip itself.

Refs #162

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ADR-0034 supersedes the ask tier of ADR-0031 now that the sandbox is the hard boundary.

Closes #162

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 15, 2026 06:50

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@furedea
furedea merged commit e85d76b into main Oct 15, 2026
11 checks passed
@furedea
furedea deleted the feat/ask-only-for-effects-outside-the-sandbox branch October 15, 2026 07:00
furedea added a commit that referenced this pull request Oct 15, 2026
…#165)

## Summary

Claude Code matches its allow rules against every command in a call, so
`cd repo && rg foo`, a pipeline into `sed`, `awk`, or `xargs`, and plain
`cp`/`mv` were never rule-matched: `cd`, `sed` (without `-n` or `-i`),
`awk`, `xargs`, `cp`, and `mv` had no allow entry. In auto mode the
classifier then decided and sometimes prompted; in every other mode the
call always prompted. That is where the remaining `rg`/`grep`/`jq`
prompts came from after #163.

All six are contained by the sandbox under ADR-0034:

- `cd`: the verification scope check still asks for a target outside the
worktree and temp directories, and for a run-time target.
- `sed`, `awk`: writes stay inside the worktree, where Git restores
tracked files; `sed -i` was already allowed.
- `xargs`: the hooks already unwrap it and judge the wrapped command, so
`xargs git add -A` is still forbidden.
- `cp`, `mv`: replace the `-n`-only forms; the sandbox confines writes,
and a glob or variable argument still asks.

Closes #164

## Verification

- `uv run --frozen pytest tests/agents`: 1502 passed.
- `ruff check`, `ruff format --check`, and dprint are clean; lefthook
pre-commit and commitlint passed.
- Live check after `home-manager switch`, in a new session: `cd agents
&& rg -n foo lib` and `find . -name '*.py' | xargs grep -l foo` should
run without a prompt; `cp *.md backup/` should ask.

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

Co-authored-by: Claude Fable 5.1 <[email protected]>
furedea added a commit that referenced this pull request Nov 12, 2026
agent-config の最新を取り込みます.#74 のモデル判定の改善がまとめて入ります.#452 の置き換えです(#452 はこの PR
の前の版の `flake.lock` でした).

| 取り込む変更(furedea/agent-config) | 中身 |
| --- | --- |
| #157 | Stop に判定の秒数を出す.`model-rules/**/fixtures/**` をモデル判定に送らない |
| #160 | `model-rules/*/fixtures/*` をテストの検証で数えない |
| #163 | Python と TypeScript の誤検知を直す(M-05 は原則の書き直しと基準値,M-21 は送る範囲を
`located` に) |
| #167 | 保存結果の数を下見から取る |
| #158 | Go と Rust の M-05,M-21,M-60 を追加.保存した基準を相対パスで取り直した |
| #170 | Stop の表示を `jev-lint: 0 findings · 74 subjects · passed ·
$0.0004 · 4.3s` の 1 行にする |

- [x] `darwin-rebuild switch` で反映済み

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

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Ask only for effects that escape the sandbox

2 participants