You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@magpie.apache.org by po...@apache.org on 2026/09/21 02:40:59 UTC

(magpie) branch main updated: fix(sandbox): use Edit(path) for file denies, add the eval exclusion (#1311)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/magpie.git


The following commit(s) were added to refs/heads/main by this push:
     new 5c75abd2 fix(sandbox): use Edit(path) for file denies, add the eval exclusion (#1311)
5c75abd2 is described below

commit 5c75abd216d798efce7257749cbdb3e26844b3c0
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Mon Sep 21 04:40:53 2026 +0200

    fix(sandbox): use Edit(path) for file denies, add the eval exclusion (#1311)
    
    `Write(path)` rules are not matched by the file permission check — only
    `Edit(path)` is, and it already covers every file-editing tool. The two
    `Write(…)` denies on the vetted-ops catalogue and policy were therefore
    dead config that read as a second layer of protection, and Claude Code
    now warns about them at startup. Drop them, and correct the install
    recipe, tool README, docs and lint baseline that emit them. The same
    correction applies to the `MultiEdit(…)` pair the secure-setup doc
    showed for `.claude/settings.json`.
    
    Also adds an optional exclusion so eval suites can be graded by
    `claude -p` from inside the sandbox, which otherwise denies the nested
    CLI its credentials and turns every case into an ERROR.
    
    `--cli` takes an arbitrary shell command, so excluding the runner would
    carve out `--cli "curl …"` rather than the eval harness, and pinning
    `--cli` in the exclusion pattern does not hold because argparse is
    last-wins. A wrapper fixes the CLI instead and accepts one positional
    path under `evals/`, no flags. Since an exclusion runs whatever the
    command executes outside the sandbox, the wrapper and the runner
    package are installed to `~/.claude/scripts/` — outside every
    allowWrite root — exactly as container-gateway already does, with
    `Edit(~/.claude/scripts/**)` closing the agent's editing tools over the
    same directory. An in-repo wrapper could not carry that guarantee: it
    matters only for what it execs, so the runner's whole source tree would
    have to be denied as well.
    
    The step is optional and skipped for anyone who does not run eval
    suites; `setup-isolated-setup-verify` reports n/a rather than a gap.
    
    Also brings the sandbox spec's excludedCommands list up to date — it
    still named only `gh`, having missed the vetted-ops dispatcher from
    #1310.
    
    Generated-by: Claude Opus 5
---
 .claude/settings.json                              |   6 +-
 docs/mode-economics.md                             |   8 +-
 docs/setup/secure-agent-setup.md                   |  51 +++++---
 .../skills/isolated-setup-install/SKILL.md         |  73 ++++++++++-
 .../skills/isolated-setup-update/SKILL.md          |  16 ++-
 .../skills/isolated-setup-verify/SKILL.md          |  49 +++++++-
 tools/sandbox-lint/expected.json                   |   6 +-
 tools/skill-evals/README.md                        | 100 +++++++++++++++-
 .../case-7-signing-key-unreadable/report.md        |   2 +-
 tools/skill-evals/magpie-run-evals.sh              | 133 +++++++++++++++++++++
 tools/spec-loop/specs/agent-isolation-sandbox.md   |  35 +++++-
 tools/vetted-ops/README.md                         |   8 +-
 12 files changed, 440 insertions(+), 47 deletions(-)

diff --git a/.claude/settings.json b/.claude/settings.json
index 89a772da..d8015326 100644
--- a/.claude/settings.json
+++ b/.claude/settings.json
@@ -5,7 +5,8 @@
     "excludedCommands": [
       "gh *",
       "uv run --project tools/vetted-ops vetted-op-read *",
-      "uv run --project ~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/*/tools/vetted-ops vetted-op-read *"
+      "uv run --project ~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/*/tools/vetted-ops vetted-op-read *",
+      "~/.claude/scripts/magpie-run-evals.sh *"
     ],
     "filesystem": {
       "denyRead": [
@@ -123,9 +124,8 @@
       "Edit(.claude/settings.json)",
       "Edit(.claude/settings.local.json)",
       "Edit(.apache-magpie-overrides/tools/vetted-ops/**)",
-      "Write(.apache-magpie-overrides/tools/vetted-ops/**)",
       "Edit(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
-      "Write(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
+      "Edit(~/.claude/scripts/**)",
       "Bash(curl *)",
       "Bash(wget *)",
       "Bash(aws *)",
diff --git a/docs/mode-economics.md b/docs/mode-economics.md
index 0d9a958d..b37c90ba 100644
--- a/docs/mode-economics.md
+++ b/docs/mode-economics.md
@@ -92,7 +92,7 @@ special-token spellings counted as ordinary text.
 Coverage: **75 of 75 local `skills/*/SKILL.md` files**.
 External `source.md` redirects and harness symlinks are excluded.
 
-Measurement manifest SHA-256: `025b473aca2cddcd3304dfc5adbda35c972e51c0039ad790437528e3e047060c`.
+Measurement manifest SHA-256: `ff0639052281a5f8336b83b048cd57b403f3f3b5dad5f255093600a74ef5cd18`.
 
 | Skill file | Measured tokens | Source SHA-256 (first 16 characters) |
 |---|---:|---|
@@ -160,9 +160,9 @@ Measurement manifest SHA-256: `025b473aca2cddcd3304dfc5adbda35c972e51c0039ad7904
 | [security-tracker-stats-dashboard](../skills/security-tracker-stats-dashboard/SKILL.md) | 4,897 | `b52154deb8557ba4` |
 | [setup](../skills/setup/SKILL.md) | 8,724 | `82788542bb240309` |
 | [setup-isolated-setup-doctor](../skills/setup-isolated-setup-doctor/SKILL.md) | 7,950 | `3fa5d728fa080ed0` |
-| [setup-isolated-setup-install](../skills/setup-isolated-setup-install/SKILL.md) | 10,110 | `c32091305674dd2b` |
-| [setup-isolated-setup-update](../skills/setup-isolated-setup-update/SKILL.md) | 4,843 | `60bab0e30ac2e25a` |
-| [setup-isolated-setup-verify](../skills/setup-isolated-setup-verify/SKILL.md) | 7,489 | `d7fa414b358d90ad` |
+| [setup-isolated-setup-install](../skills/setup-isolated-setup-install/SKILL.md) | 10,915 | `e806b0f1d0be8f03` |
+| [setup-isolated-setup-update](../skills/setup-isolated-setup-update/SKILL.md) | 5,036 | `a2317a80efccf5c8` |
+| [setup-isolated-setup-verify](../skills/setup-isolated-setup-verify/SKILL.md) | 8,149 | `4dfa606de85da6ff` |
 | [setup-override-upstream](../skills/setup-override-upstream/SKILL.md) | 4,012 | `fb583feb56b7f77c` |
 | [setup-privacy-llm](../skills/setup-privacy-llm/SKILL.md) | 2,145 | `0e27b542a1656846` |
 | [setup-shared-config-sync](../skills/setup-shared-config-sync/SKILL.md) | 4,357 | `d1dfcd7cdeb5f5a6` |
diff --git a/docs/setup/secure-agent-setup.md b/docs/setup/secure-agent-setup.md
index bd641ec2..a940ab02 100644
--- a/docs/setup/secure-agent-setup.md
+++ b/docs/setup/secure-agent-setup.md
@@ -641,10 +641,11 @@ below, annotated.
       // is therefore sandbox-writable. That is tolerable only because the read
       // dispatcher ignores policy when refusing writes: editing the policy can
       // widen which repo is READ, never turn a read into a write.
+      // One rule per surface, not two: `Edit(path)` is the path rule for
+      // every file-writing tool (Write and NotebookEdit included), and a
+      // `Write(path)` rule is not matched by the file permission check at all.
       "Edit(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
-      "Write(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
-      "Edit(.apache-magpie-overrides/tools/vetted-ops/**)",
-      "Write(.apache-magpie-overrides/tools/vetted-ops/**)"
+      "Edit(.apache-magpie-overrides/tools/vetted-ops/**)"
     ],
     "ask": [
       "Bash(git push *)",                        // including --force / --force-with-lease variants
@@ -876,23 +877,27 @@ harness owns it. So a sandboxed Bash invocation, even one running
 attacker-chosen code, cannot mutate `.claude/settings.local.json`
 to broaden the next session's sandbox.
 
-**2. Edit / Write / MultiEdit agent tools bypass the sandbox.**
-These tools call into the harness directly, not through a Bash
-subprocess, so the sandbox's `denyWithinAllow` does not apply. The
-framework closes the bypass by adding the per-tool denies in the
-committed `.claude/settings.json`:
+**2. The agent's file-editing tools bypass the sandbox.**
+Edit, Write and NotebookEdit call into the harness directly, not
+through a Bash subprocess, so the sandbox's `denyWithinAllow` does
+not apply. The framework closes the bypass by adding path denies in
+the committed `.claude/settings.json`:
 
 ```jsonc
 "deny": [
   "Edit(.claude/settings.json)",
-  "Edit(.claude/settings.local.json)",
-  "Write(.claude/settings.json)",
-  "Write(.claude/settings.local.json)",
-  "MultiEdit(.claude/settings.json)",
-  "MultiEdit(.claude/settings.local.json)"
+  "Edit(.claude/settings.local.json)"
 ]
 ```
 
+Two rules, not six. In `permissions`, `Edit(path)` is *the* path
+rule for file writes and covers every file-editing tool; a
+`Write(path)` or `NotebookEdit(path)` rule is not matched by the
+file permission check, so listing one alongside protects nothing and
+misleads the next reader into thinking the surface is covered twice.
+(Bare tool names — `"Write"` — and `Tool(param:value)` deny / ask
+rules still use each tool's own name.)
+
 A compromised agent that tries `Edit('.claude/settings.local.json', ...)`
 hits the deny rule and the call fails. The denies are committed at
 project scope, so every contributor inherits them; an adopter who
@@ -2977,10 +2982,14 @@ below and report ✓ done / ✗ missing / ⚠ partial, with the evidence
      is ✗ and worth stopping for: it grants every operation in
      the catalogue, because the operation's caller name is chosen
      by whoever runs the command.
-   - `permissions.deny` denies `Edit` and `Write` on both
+   - `permissions.deny` denies `Edit` on both
      `~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**`
      (the catalogue) and
      `.apache-magpie-overrides/tools/vetted-ops/**` (the policy).
+     One `Edit` rule per surface is the whole coverage — it binds
+     every file-editing tool. A `Write(…)` rule sitting next to it
+     is dead weight the file permission check never consults;
+     report it as cruft to remove, not as a second layer.
    If the repo has no vetted-ops policy at all, report n/a.
 10. If a hardware key signs my commits or authenticates my git
     remotes: the touch overlay is wired (`PreToolUse` /
@@ -3035,6 +3044,20 @@ below and report ✓ done / ✗ missing / ⚠ partial, with the evidence
     On any ✗, point at
     [`docs/setup/sandbox-troubleshooting.md` → Docker / Podman command fails with a socket error](sandbox-troubleshooting.md#docker--podman-command-fails-with-a-socket-error)
     rather than re-explaining the fix.
+13. **Eval-harness exclusion**, if installed (optional — report
+    n/a when neither the exclusion nor the script is present;
+    not running eval suites is a normal posture). When either is:
+    `sandbox.excludedCommands` contains
+    `"~/.claude/scripts/magpie-run-evals.sh *"`,
+    `~/.claude/scripts/magpie-run-evals.sh` exists and is
+    executable, `~/.claude/scripts/skill-evals/src/skill_evals/`
+    sits beside it, and `permissions.deny` contains
+    `Edit(~/.claude/scripts/**)`. Either half of the
+    exclusion/script pair alone is ✗, as is a missing deny — the
+    exclusion runs that code outside the sandbox, so it must not
+    be agent-writable. Copies that differ from
+    `tools/skill-evals/` are ⚠, not ✗: the harness runs, it just
+    grades against an older runner than the tree's.
 ```
 
 Re-run either form after every Claude Code upgrade — the sandbox
diff --git a/plugins/magpie-setup/skills/isolated-setup-install/SKILL.md b/plugins/magpie-setup/skills/isolated-setup-install/SKILL.md
index b57bae7c..2fc972c5 100644
--- a/plugins/magpie-setup/skills/isolated-setup-install/SKILL.md
+++ b/plugins/magpie-setup/skills/isolated-setup-install/SKILL.md
@@ -588,12 +588,15 @@ writes structurally.
     "Bash(uv run --project ~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/*/tools/vetted-ops vetted-op *)"
   ],
   "deny": [
+    // `Edit(path)` is the path rule for every file-writing tool — Write and
+    // NotebookEdit included. A `Write(path)` rule is NOT matched by the file
+    // permission check; do not add one alongside, it reads as a second layer
+    // that is not there.
+    //
     // the operation catalogue — the read `allow` rests on its shape
     "Edit(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
-    "Write(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
     // the policy naming which caller may run which operation
-    "Edit(.apache-magpie-overrides/tools/vetted-ops/**)",
-    "Write(.apache-magpie-overrides/tools/vetted-ops/**)"
+    "Edit(.apache-magpie-overrides/tools/vetted-ops/**)"
   ]
 }
 ```
@@ -765,6 +768,70 @@ Tell the operator plainly, every time this step runs:
 Verification of all four pieces is check 12 of
 `setup-isolated-setup-verify`; hand off rather than re-checking here.
 
+## Step M — the eval-harness exclusion (optional)
+
+**Offer this only when the operator runs Magpie's eval suites** —
+framework contributors, and adopters who maintain agentic overrides
+and want the suites graded by a model. Everyone else should decline;
+the step adds an unsandboxed command for no benefit. If the repo has
+no `tools/skill-evals/`, skip it silently.
+
+The problem it solves: `--cli` mode needs the model CLI's
+credentials, which the sandbox denies, so an agent that runs a suite
+itself gets one `ERROR` per case rather than a grade.
+
+**M.1 — Copy the wrapper and the package it runs.** Same shape as
+L.1, and for the same reason. Copy
+`tools/skill-evals/magpie-run-evals.sh` into `~/.claude/scripts/`,
+`chmod +x` it, and copy the whole package
+`tools/skill-evals/src/skill_evals/` to
+`~/.claude/scripts/skill-evals/src/skill_evals/` beside it. The
+wrapper finds the package by looking next to itself.
+
+**M.2 — The exclusion and the deny.** Propose, as one diff:
+
+```jsonc
+"sandbox": {
+  "excludedCommands": ["~/.claude/scripts/magpie-run-evals.sh *"]
+},
+"permissions": {
+  "deny": ["Edit(~/.claude/scripts/**)"]
+}
+```
+
+Say why the copy is not optional, because it is the whole point of
+the step:
+
+- An exclusion makes whatever the command executes run **outside**
+  the sandbox, so that code must not be writable by the thing being
+  sandboxed. `~/.claude/scripts/` is outside every
+  `sandbox.filesystem.allowWrite` root, so the copies are already
+  beyond sandboxed Bash; the `Edit` deny closes the agent's own
+  editing tools over the same directory.
+- Excluding the runner **in the repository** instead fails twice
+  over. `--cli` is an arbitrary shell command, so the exclusion
+  would carve out `--cli "curl …"`, not the eval harness — and
+  pinning `--cli` in the pattern does not hold, because argparse is
+  last-wins. An `Edit` deny on an in-repo wrapper does not rescue
+  it either: the wrapper matters only for what it executes, so the
+  runner's whole source tree would need denying too.
+- Remember the coupling when *any* in-repo path gets a deny: it
+  becomes a sandbox write-deny, so the path must also join the
+  `sandbox_write_denied` anchor in `.pre-commit-config.yaml`, or
+  `end-of-file-fixer`, `mixed-line-ending` and `trailing-whitespace`
+  abort `prek run --all-files`. Out-of-tree paths like
+  `~/.claude/scripts/**` need no such entry.
+- The wrapper takes exactly one positional path under `evals/` and
+  no flags. That shape is what the exclusion is trusting. Any other
+  eval invocation stays on the `!` prefix, outside the sandbox.
+- **The copy goes stale.** Re-run M.1 after changing the runner, or
+  the suites run from inside the sandbox are the old ones. Drift is
+  check 13 of `setup-isolated-setup-verify` and a line in
+  `setup-isolated-setup-update`.
+
+Full rationale:
+[`tools/skill-evals/README.md` → Running from inside the sandbox](../../../../tools/skill-evals/README.md#running-from-inside-the-sandbox).
+
 ## After the install lands
 
 **Tell the operator what to look for in the footer**, and what each
diff --git a/plugins/magpie-setup/skills/isolated-setup-update/SKILL.md b/plugins/magpie-setup/skills/isolated-setup-update/SKILL.md
index 1a720a04..b3afccb5 100644
--- a/plugins/magpie-setup/skills/isolated-setup-update/SKILL.md
+++ b/plugins/magpie-setup/skills/isolated-setup-update/SKILL.md
@@ -195,6 +195,14 @@ Walk each:
    `tools/container-gateway/src/container_gateway/` — a stale copy
    here is a silent behaviour drift, not the no-op a missing copy
    is, so it is worth the same drift check as any other script),
+   `~/.claude/scripts/magpie-run-evals.sh` with the package it runs,
+   `~/.claude/scripts/skill-evals/src/skill_evals/`, where the
+   optional eval-harness exclusion is installed (diff against
+   `tools/skill-evals/magpie-run-evals.sh` and
+   `tools/skill-evals/src/skill_evals/`, ignoring `__pycache__`;
+   absent on both sides is not drift, it is the default posture —
+   but a stale copy is the worst case here, because the suites keep
+   passing while grading against an older runner than the tree's),
    **and** —
    *only when whole-user scope is in effect, detected via
    `git config --global --get core.hooksPath` resolving to
@@ -320,12 +328,16 @@ invocation passes is chosen by whoever runs it. Report that as a
 must-fix, ahead of anything else in this section.
 
 **Second, `permissions.deny` still covers both surfaces**, each with
-`Edit` and `Write`:
+an `Edit` rule:
 
 - `~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**`
 - `.apache-magpie-overrides/tools/vetted-ops/**`
 
-Report a missing rule as drift to repair, not a note. This is the
+Report a missing rule as drift to repair, not a note. A leftover
+`Write(…)` rule on either path is the opposite kind of drift —
+`Edit(path)` already binds every file-editing tool and a
+`Write(path)` rule is not matched by the file permission check, so
+surface it as cruft to delete. This is the
 check most likely to rot in practice: the plugin-cache path carries
 the plugin *name*, so a family rename or a move of the dispatcher to
 a different substrate plugin leaves a deny rule that still looks
diff --git a/plugins/magpie-setup/skills/isolated-setup-verify/SKILL.md b/plugins/magpie-setup/skills/isolated-setup-verify/SKILL.md
index 4c5945d8..efd96eb6 100644
--- a/plugins/magpie-setup/skills/isolated-setup-verify/SKILL.md
+++ b/plugins/magpie-setup/skills/isolated-setup-verify/SKILL.md
@@ -312,14 +312,19 @@ Walk each in order:
    `vetted-op` in `ask` (or absent) is correct.
 
    **9b — the exclusion.** `permissions.deny` covers both surfaces,
-   each with `Edit` and `Write`:
+   each with an `Edit` rule:
 
    - `~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**` —
      the operation catalogue. The read dispatcher's `allow` rests on
      its shape, so an editable catalogue dissolves that `allow`.
    - `.apache-magpie-overrides/tools/vetted-ops/**` — the policy.
 
-   Any of the four missing is ✗.
+   Either one missing is ✗. One `Edit` rule per surface is the whole
+   coverage — in `permissions`, `Edit(path)` binds every file-editing
+   tool, and a `Write(path)` rule is not matched by the file
+   permission check at all. A `Write(…)` line beside an `Edit(…)` is
+   therefore a note, not a pass: it protects nothing and reads as a
+   second layer that is not there.
 
    Report two things as **notes**, not failures. The policy's
    protection stops at the agent's editing tools — it sits in the
@@ -481,6 +486,46 @@ Walk each in order:
     [`docs/setup/sandbox-troubleshooting.md` → Docker / Podman command fails with a socket error](../../../../docs/setup/sandbox-troubleshooting.md#docker--podman-command-fails-with-a-socket-error)
     rather than re-explaining the fix.
 
+13. **Eval-harness exclusion, if installed.** Optional (step M of
+    `setup-isolated-setup-install`): report **n/a** when
+    `sandbox.excludedCommands` has no
+    `~/.claude/scripts/magpie-run-evals.sh *` entry *and*
+    `~/.claude/scripts/magpie-run-evals.sh` is absent. Not running
+    eval suites is a normal posture, not a gap.
+
+    When either is present, all of it must be:
+
+    - **13a — both halves, or neither.** The exclusion entry and the
+      installed wrapper must agree. An exclusion naming a script that
+      is not there is dead config; an installed script with no
+      exclusion silently runs sandboxed and reports `Not logged in`
+      for every case. Either alone is ✗, naming which half is missing.
+    - **13b — the package is beside the wrapper.**
+      `~/.claude/scripts/skill-evals/src/skill_evals/` exists.
+      Missing is ✗: the wrapper exits 2 without it, so no suite can
+      run.
+    - **13c — the copies match the repository.** Hash-compare
+      `~/.claude/scripts/magpie-run-evals.sh` against
+      `tools/skill-evals/magpie-run-evals.sh`, and every `*.py` under
+      `~/.claude/scripts/skill-evals/src/skill_evals/` against
+      `tools/skill-evals/src/skill_evals/` (ignore `__pycache__`).
+      Any difference is ⚠, not ✗, and names the drifted files: the
+      harness still runs, it just runs an older grader than the one
+      in the tree. Remedy is re-running install step M.1.
+    - **13d — the deny is present.** `permissions.deny` contains
+      `Edit(~/.claude/scripts/**)`. Missing is ✗ — without it the
+      agent can edit the very code the exclusion runs outside the
+      sandbox, which is the whole bargain of the step.
+
+    Report as a **note**, not a failure: the eval *fixtures* stay
+    agent-writable in the repository by design. They are data the
+    runner reads, never code it executes, so a fixture edit is a
+    review problem visible in the diff rather than a sandbox escape.
+    If a report describes the fixtures as protected, correct it.
+
+    Rationale:
+    [`tools/skill-evals/README.md` → Running from inside the sandbox](../../../../tools/skill-evals/README.md#running-from-inside-the-sandbox).
+
 ## After the report
 
 If every check is ✓, say so explicitly and stop — no further
diff --git a/tools/sandbox-lint/expected.json b/tools/sandbox-lint/expected.json
index 89a772da..d8015326 100644
--- a/tools/sandbox-lint/expected.json
+++ b/tools/sandbox-lint/expected.json
@@ -5,7 +5,8 @@
     "excludedCommands": [
       "gh *",
       "uv run --project tools/vetted-ops vetted-op-read *",
-      "uv run --project ~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/*/tools/vetted-ops vetted-op-read *"
+      "uv run --project ~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/*/tools/vetted-ops vetted-op-read *",
+      "~/.claude/scripts/magpie-run-evals.sh *"
     ],
     "filesystem": {
       "denyRead": [
@@ -123,9 +124,8 @@
       "Edit(.claude/settings.json)",
       "Edit(.claude/settings.local.json)",
       "Edit(.apache-magpie-overrides/tools/vetted-ops/**)",
-      "Write(.apache-magpie-overrides/tools/vetted-ops/**)",
       "Edit(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
-      "Write(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
+      "Edit(~/.claude/scripts/**)",
       "Bash(curl *)",
       "Bash(wget *)",
       "Bash(aws *)",
diff --git a/tools/skill-evals/README.md b/tools/skill-evals/README.md
index 0fd07eee..0b6da176 100644
--- a/tools/skill-evals/README.md
+++ b/tools/skill-evals/README.md
@@ -100,12 +100,15 @@ Suites are currently implemented for:
   grading adds a judge CLI (default `claude -p --model haiku`).
 - **Credentials / auth:** None in print mode; in `--cli` mode whatever
   the chosen model CLI requires (e.g. a Claude / API key, or a local
-  Ollama install). **Run `--cli` mode outside any sandbox that denies
-  the CLI its credentials.** An agent sandbox typically blocks the
-  keychain and `~/.claude.json`, so `claude -p` returns `Not logged in`;
-  every case then reports ERROR with "nothing was graded" (see *JSON
-  extraction* below). Before that guard existed the same situation
-  reported a green run.
+  Ollama install). **`--cli` mode needs to run outside any sandbox that
+  denies the CLI its credentials.** An agent sandbox typically blocks
+  the keychain and `~/.claude.json`, so `claude -p` returns
+  `Not logged in`; every case then reports ERROR with "nothing was
+  graded" (see *JSON extraction* below). Before that guard existed the
+  same situation reported a green run. Two ways out: run the command
+  yourself with the `!` prefix, or — for the `claude -p` case only —
+  use [`run-evals.sh`](#running-from-inside-the-sandbox), which the
+  framework's own sandbox config excludes.
 - **Network:** Evals mock all external tool calls, so the harness itself
   makes no network calls; any network use comes from the model CLI you
   point `--cli` / `--grader-cli` at.
@@ -170,6 +173,91 @@ PYTHONPATH=tools/skill-evals/src python3 -m skill_evals.runner --tag local-smoke
 # (or --cli "ollama run llama3.1:8b --nowordwrap --format json")
 ```
 
+### Running from inside the sandbox
+
+Everything above assumes a shell with the model CLI's credentials. An
+agent running under the framework's [secure
+setup](../../docs/setup/secure-agent-setup.md) does not have them, so
+an agent that types one of those command lines gets one `ERROR` per
+case. [`magpie-run-evals.sh`](magpie-run-evals.sh) is the one shape it
+can run itself:
+
+```bash
+~/.claude/scripts/magpie-run-evals.sh tools/skill-evals/evals/<skill>/
+~/.claude/scripts/magpie-run-evals.sh tools/skill-evals/evals/<skill>/<step>/fixtures/<case>
+```
+
+The framework's `.claude/settings.json` lists
+`~/.claude/scripts/magpie-run-evals.sh *` in
+`sandbox.excludedCommands`, so that call runs outside the sandbox and
+the nested `claude -p` reaches the keychain. Paths are relative to the
+current directory — run it from the repository root.
+
+**It is a user-scope copy, like the touch overlay.** The file in this
+directory is the source of truth; installing it copies both the
+wrapper and the runner package to `~/.claude/scripts/`:
+
+```text
+~/.claude/scripts/magpie-run-evals.sh        <- tools/skill-evals/magpie-run-evals.sh
+~/.claude/scripts/skill-evals/src/skill_evals/  <- tools/skill-evals/src/skill_evals/
+```
+
+The package keeps its `src/` shape under a named directory, matching
+how `container-gateway` is installed.
+
+`setup-isolated-setup-install` performs the copy,
+`setup-isolated-setup-verify` hash-compares it, and
+`setup-isolated-setup-update` reports drift — the same treatment
+`tools/agent-isolation/gpg-touch-overlay.sh` gets. **Re-run the copy
+after changing the runner**, or the evals you run from inside the
+sandbox are the old ones.
+
+**Why the executed code lives outside the repository.** Excluding a
+command makes whatever it executes run unsandboxed, so that code must
+not be writable by the thing being sandboxed. Two simpler shapes fail
+that test:
+
+- *Excluding the runner directly.* `--cli` is an arbitrary shell
+  command, so the exclusion would not carve out the eval harness — it
+  would carve out `--cli "curl …"`. Pinning `--cli` inside the
+  exclusion *pattern* does not help: argparse is last-wins, so a
+  second `--cli` later on the line still matches the prefix.
+- *Excluding an in-repo wrapper and denying edits to it.* A deny stops
+  the agent's editing tools, but the wrapper is only half the story —
+  it `exec`s the runner, so `tools/skill-evals/src/**` would need
+  denying too, and that is a tree under active development in this
+  repository. (The mechanical side of an in-repo deny is already
+  solved and is not the objection: `Edit(path)` denies merge into
+  `sandbox.filesystem.denyWrite`, so such a path must also join the
+  `sandbox_write_denied` anchor in `.pre-commit-config.yaml`, or
+  `end-of-file-fixer` and its two siblings abort `prek run
+  --all-files` — see #1309. Those three hooks then stop covering the
+  file.)
+
+`~/.claude/scripts/` sits outside every `allowWrite` root, so the
+copies are unwritable from sandboxed Bash without any deny rule
+touching a tracked path; `Edit(~/.claude/scripts/**)` closes the
+agent's editing tools over the same directory.
+
+**What is still in reach.** The fixtures stay in the repository and
+stay agent-writable. They are data — the runner reads them, renders
+prompts, and pipes text to `claude -p`; nothing under `evals/` is
+executed. Editing a fixture can change what a case asserts, which is a
+review problem visible in the diff, not a sandbox escape.
+
+Two gotchas, both shared with the `gh *` exclusion:
+
+- Call it by that exact path, alone on the line. `bash ~/…`, a
+  relative spelling, or any pipe, redirect or `$(…)` in the same
+  command stops the invocation matching the exclusion, and it runs
+  sandboxed again — reported, confusingly, as `Not logged in`.
+- A full suite takes minutes. Run it in the background rather than
+  wrapping it in `| tail`, which would break the match.
+
+For any other shape — `--verbose`, `--tag`, a non-Claude `--cli`, a
+different `--grader-cli` — run the runner directly with the `!`
+prefix, outside the sandbox.
+
 **JSON extraction** tries three strategies in order: parse the whole
 stdout as JSON, look for the first ```` ```json ```` fenced block, then
 the largest balanced `{...}` (or `[...]`) substring. Models that wrap
diff --git a/tools/skill-evals/evals/setup-isolated-setup-verify/step-1-classify/fixtures/case-7-signing-key-unreadable/report.md b/tools/skill-evals/evals/setup-isolated-setup-verify/step-1-classify/fixtures/case-7-signing-key-unreadable/report.md
index 19e95d77..4769ba98 100644
--- a/tools/skill-evals/evals/setup-isolated-setup-verify/step-1-classify/fixtures/case-7-signing-key-unreadable/report.md
+++ b/tools/skill-evals/evals/setup-isolated-setup-verify/step-1-classify/fixtures/case-7-signing-key-unreadable/report.md
@@ -63,7 +63,7 @@ Live probe: read .git/HEAD OK; write .magpie-verify-probe.tmp OK (removed).
 ## Check 9 — vetted-ops split and exclusion
 
 permissions.allow contains vetted-op-read only; vetted-op is in ask.
-permissions.deny has Edit + Write on ~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/** and .apache-magpie-overrides/tools/vetted-ops/**.
+permissions.deny has Edit on ~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/** and .apache-magpie-overrides/tools/vetted-ops/**.
 
 ## Check 10 — Hardware-key touch overlay and the signing key
 
diff --git a/tools/skill-evals/magpie-run-evals.sh b/tools/skill-evals/magpie-run-evals.sh
new file mode 100755
index 00000000..7956b7ff
--- /dev/null
+++ b/tools/skill-evals/magpie-run-evals.sh
@@ -0,0 +1,133 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# magpie-run-evals.sh — run one eval suite, step, or case against
+# `claude -p` from inside the agent sandbox.
+#
+# THIS FILE IS THE SOURCE OF TRUTH FOR A USER-SCOPE COPY.
+# The copy at ~/.claude/scripts/magpie-run-evals.sh is what
+# `sandbox.excludedCommands` names, alongside a copy of the runner
+# package at ~/.claude/scripts/skill_evals/. Same idiom as
+# tools/agent-isolation/gpg-touch-overlay.sh; `setup-isolated-setup-verify`
+# hash-compares the copies against these originals, and
+# `setup-isolated-setup-update` reports drift.
+#
+# WHY THE EXECUTED CODE LIVES OUTSIDE THE REPOSITORY
+#
+# Excluding a command from the sandbox makes whatever that command
+# executes run unsandboxed, so the executed code must not be writable
+# by the thing being sandboxed. Two earlier shapes fail that test:
+#
+#   - Excluding the eval runner directly. `--cli` is an arbitrary
+#     shell command, so the exclusion would not carve out the eval
+#     harness, it would carve out `--cli "curl …"`. Pinning `--cli`
+#     inside the exclusion *pattern* does not help either: argparse is
+#     last-wins, so a second `--cli` later on the line still matches
+#     the prefix.
+#
+#   - Excluding an in-repo wrapper and denying edits to it. A deny
+#     stops the agent's editing tools, but the wrapper only matters
+#     because of what it `exec`s, so tools/skill-evals/src/** would
+#     have to be denied as well — a tree this repository develops.
+#     (The mechanical cost of an in-repo deny is already handled and
+#     is not the objection: `Edit(path)` denies merge into
+#     `sandbox.filesystem.denyWrite`, so the path must also join the
+#     `sandbox_write_denied` anchor in `.pre-commit-config.yaml` or
+#     the three whitespace hooks abort `prek run --all-files`, per
+#     #1309 — at the cost of those hooks no longer covering it.)
+#
+# ~/.claude/scripts/ is outside every `sandbox.filesystem.allowWrite`
+# root, so the copies are already unwritable from sandboxed Bash
+# without any deny rule touching a tracked path;
+# `Edit(~/.claude/scripts/**)` closes the agent's editing tools over
+# the same directory.
+#
+# WHAT IS STILL IN REACH, AND WHY THAT IS ACCEPTABLE
+#
+# The eval *fixtures* stay in the repository and remain agent-writable.
+# They are data: the runner reads them, renders prompts, and pipes text
+# to `claude -p`. Nothing under `evals/` is executed. Editing a fixture
+# can change what a case asserts — a review problem, caught by the diff
+# — but cannot run code outside the sandbox. It can route repository
+# text to the model, which the session's own API access already allows.
+#
+# Usage, from the repository root:
+#
+#   ~/.claude/scripts/magpie-run-evals.sh tools/skill-evals/evals/<skill>/
+#   ~/.claude/scripts/magpie-run-evals.sh tools/skill-evals/evals/<skill>/<step>/fixtures/<case>
+#
+# Invoke it by that exact path, alone on the line. `bash ~/…`, a
+# relative spelling, or any pipe, redirect or `$(…)` in the same
+# command stops the call matching the exclusion and it runs sandboxed
+# again — reported, confusingly, as `Not logged in`. The same gotcha
+# the `gh *` exclusion has.
+set -euo pipefail
+
+readonly EVALS_REL="tools/skill-evals/evals"
+
+script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
+
+# Installed layout mirrors container-gateway's — the package keeps its
+# src/ shape under a named directory beside this script. In-repo layout
+# (running the original rather than the copy) is this file's own
+# tools/skill-evals/src/. Keeping one file valid in both places lets the
+# drift check be a plain hash compare.
+if [ -d "$script_dir/skill-evals/src/skill_evals" ]; then
+  pythonpath="$script_dir/skill-evals/src"
+elif [ -d "$script_dir/src/skill_evals" ]; then
+  pythonpath="$script_dir/src"
+else
+  echo "magpie-run-evals.sh: no skill_evals package found near $script_dir" >&2
+  echo "  reinstall the user-scope copy — see tools/skill-evals/README.md" >&2
+  exit 2
+fi
+
+usage() {
+  cat >&2 <<EOF
+usage: magpie-run-evals.sh <path-under-$EVALS_REL/>
+
+Runs the eval runner over exactly that path with --cli "claude -p",
+from the current directory (the repository root).
+
+Takes one argument and accepts no flags, because the exclusion that
+lets this run unsandboxed rests on that shape. For any other shape
+— --verbose, --tag, a different --cli or --grader-cli — call the
+runner directly with the ! prefix, outside the sandbox:
+
+  PYTHONPATH=tools/skill-evals/src python3 -m skill_evals.runner --help
+EOF
+  exit 2
+}
+
+[ "$#" -eq 1 ] || usage
+
+target="$1"
+case "$target" in
+  -* | *..*) usage ;;
+  "$EVALS_REL" | "$EVALS_REL"/*) ;;
+  *) usage ;;
+esac
+
+[ -d "$target" ] || {
+  echo "magpie-run-evals.sh: no such eval path: $target" >&2
+  echo "  run from the repository root; paths are relative to it" >&2
+  exit 2
+}
+
+export PYTHONPATH="$pythonpath"
+exec python3 -m skill_evals.runner --cli "claude -p" -- "$target"
diff --git a/tools/spec-loop/specs/agent-isolation-sandbox.md b/tools/spec-loop/specs/agent-isolation-sandbox.md
index b1ae6796..42ac9919 100644
--- a/tools/spec-loop/specs/agent-isolation-sandbox.md
+++ b/tools/spec-loop/specs/agent-isolation-sandbox.md
@@ -129,12 +129,35 @@ The reference model is four layers, layered:
 2. **Filesystem + network sandbox** — Linux `bubblewrap` + `socat` SNI
    proxy; macOS `sandbox-exec`. Default-deny reads outside the tree and
    egress to non-allowed hosts. `sandbox.excludedCommands` carves out
-   commands that need host auth the sandbox blocks — `gh` (OS keyring
-   and, on macOS, Security.framework TLS verification); the blast
-   radius is held by layers 3 (`gh auth token` / `gh auth refresh`
-   denied) and 4 (`gh` writes gated by `ask`). The exemption applies
-   only to invocations made of `cd …` / `gh …` parts; the shape rule
-   and its failure signature are in
+   commands that need host auth the sandbox blocks:
+   - `gh` (OS keyring and, on macOS, Security.framework TLS
+     verification); the blast radius is held by layers 3 (`gh auth
+     token` / `gh auth refresh` denied) and 4 (`gh` writes gated by
+     `ask`).
+   - the vetted-ops **read** dispatcher, which spawns `gh` and so
+     inherits the same need; only the read dispatcher, never
+     `vetted-op` itself, because `--caller` is argv.
+   - `~/.claude/scripts/magpie-run-evals.sh` (optional), so a suite
+     can be graded by `claude -p` from inside the sandbox.
+
+   An exclusion runs whatever the command executes **outside** the
+   sandbox, so the executed code must not be writable by the thing
+   being sandboxed. Both non-`gh` entries above therefore address code
+   outside the repository — the plugin cache and `~/.claude/scripts/`,
+   neither inside any `allowWrite` root — with `permissions.deny`
+   `Edit(…)` rules over the same paths. An in-repo path cannot carry
+   that guarantee: without a deny the agent rewrites what runs
+   unsandboxed, and a deny only stops the agent's editing tools while
+   the file stays in a tree the agent can otherwise reach. The
+   mechanical cost is separate and already solved — an `Edit(path)`
+   deny merges into `sandbox.filesystem.denyWrite`, so an in-repo
+   denied path must also join the `sandbox_write_denied` anchor in
+   `.pre-commit-config.yaml` or the three whitespace hooks abort the
+   run (#1309).
+
+   The `gh` exemption applies only to invocations made of `cd …` /
+   `gh …` parts; the same whole-command shape rule governs the other
+   entries. The rule and its failure signature are in
    [`sandbox-diagnostics.md`](sandbox-diagnostics.md).
 3. **Tool permissions** — the host's `permissions.deny` blocks denied
    paths/binaries (`Read(~/.ssh/**)`, `Bash(curl *)`, …).
diff --git a/tools/vetted-ops/README.md b/tools/vetted-ops/README.md
index 72f5b7e2..897b6534 100644
--- a/tools/vetted-ops/README.md
+++ b/tools/vetted-ops/README.md
@@ -278,10 +278,12 @@ anything still invoked directly:
     "Bash(uv run --project ~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/*/tools/vetted-ops vetted-op *)"
   ],
   "deny": [
+    // `Edit(path)` is the path rule for every file-writing tool — Write and
+    // NotebookEdit included. A `Write(path)` rule is NOT matched by the file
+    // permission check, so adding one buys nothing and reads as coverage the
+    // deny list does not have.
     "Edit(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
-    "Write(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)",
-    "Edit(.apache-magpie-overrides/tools/vetted-ops/**)",
-    "Write(.apache-magpie-overrides/tools/vetted-ops/**)"
+    "Edit(.apache-magpie-overrides/tools/vetted-ops/**)"
   ]
 }
 ```