Repository navigation
fix(sbx): steer agents through the MCP server's instructions; deny only known tools - #572
Conversation
…ly known tools Claude Code never loads the CLAUDE.md that sbx up writes: the Read deny covers it, and an allow rule cannot carve an exception out of a deny. The sandbox rules now live once, in @moca/sandbox-client (sandboxRules), as the MCP server's instructions, which every client receives on connecting. The CLAUDE.md/AGENTS.md block is that same text under its heading, byte for byte the old block, so existing repositories stay current. The deny list drops MultiEdit, LS and NotebookRead: current Claude Code warns at every start about a deny naming no known tool, and those tools exist only before 2.0. sbx doctor instead fails a Claude Code on PATH older than 2.0.0. It adds Monitor, PowerShell and LSP. A Bash deny does not cover Monitor, which ran a local command in a repository configured by sbx up (checked on 2.1.304). OpenCode does not warn about unknown tools keys (1.19.3), so OPENCODE_OFF is unchanged. Fixes rossoctl#568 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Reviewed at 22875f4. The fix is sound. Sending the rules as the MCP server's instructions reaches every client whatever its permission rules. Building RULES from MCP_INSTRUCTIONS keeps the CLAUDE.md block byte-identical to the old text, and the new RULES equality test pins that. Monitor, PowerShell and LSP close a real gap (Monitor isn't covered by a Bash deny). claudeTooOld fails open on unreadable output, which is right for a check doctor lists only when it fails. CI is all green, DCO is signed off, and there are no .claude/ or .vscode/ changes.
Non-blocking:
- suggestion (docs, outside the diff):
docs/sbx/user-guide.md§8 lists every doctor check in its table (login,sandbox,agent config,exec,changes). The newclaude coderow is missing, so a user who hits it has no troubleshooting entry. One row would do: "Claude Code older than 2.0.0, whoseMultiEdit/LS/NotebookReadact on the laptop and are not denied:claude update." - suggestion (follow-up): the "Not addressed" item about already-bound repositories keeping the three warnings.
sbx uprecords what it added in its manifest, so it could remove exactly theMultiEdit/LS/NotebookReaddeny entries it wrote earlier and leave any the developer added by hand. That would clear the warnings withoutsbx rm+sbx up. Fine as a follow-up issue. - Two nits inline.
| /** `claude --version`'s output, or undefined when Claude Code is not on PATH (or did not answer). */ | ||
| export function installedClaudeVersion(): string | undefined { | ||
| try { | ||
| return execFileSync('claude', ['--version'], { |
There was a problem hiding this comment.
nit: execFileSync blocks the event loop for up to 10 s inside the async runDoctor. In practice claude --version returns quickly, so this is minor. On Windows, an npm-installed claude is a .cmd shim, and execFileSync without shell: true can't spawn it (ENOENT). That returns undefined, so the check stays silent there. Fail-open is fine, but since PowerShell is now denied with Windows in mind, it's worth either a comment noting the check is effectively POSIX-only, or execFile (async) with a .cmd fallback on win32.
There was a problem hiding this comment.
Fixed in 692bd90: installedClaudeVersion now uses execFile (async), so it no longer blocks the event loop. It passes shell: true on win32, so an npm-installed claude.cmd starts; the arguments are fixed, so the shell is safe. A new test checks that the probe is a Promise and that it returns undefined when claude isn't on PATH.
| ok: false, | ||
| detail: | ||
| `${version.split('\n')[0]} is older than ${CLAUDE_MIN_VERSION}: its MultiEdit, LS and ` + | ||
| 'NotebookRead tools act on this machine and are not denied', |
There was a problem hiding this comment.
nit: the detail says the tools "act on this machine". NotebookRead and LS only read, so "read or edit files on this machine" (or just "are not denied") would be more accurate. Wording only.
There was a problem hiding this comment.
Fixed in 692bd90: the detail now reads "read or edit files on this machine and are not denied", and the test pins the new wording.
…im; docs row Review of rossoctl#572: - installedClaudeVersion uses execFile (async), so a slow claude never blocks the event loop, with shell on win32 so an npm-installed claude.cmd starts. - The detail says the old tools "read or edit files on this machine". - docs/sbx/user-guide.md §8 gets the claude code row. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
|
Thanks for the review. Pushed 692bd90:
The mocactl suite and typecheck pass. |
| const { stdout } = await execFileAsync('claude', ['--version'], { | ||
| encoding: 'utf8', | ||
| timeout: 10_000, | ||
| shell: process.platform === 'win32', |
There was a problem hiding this comment.
nit: Node 22+ prints DEP0190 ("Passing args to a child process with shell option true…") whenever shell: true is combined with an args array, so every sbx doctor run on Windows writes a DeprecationWarning to stderr. Passing the command as one string on win32, e.g. execFileAsync(win ? 'claude --version' : 'claude', win ? [] : ['--version'], …), keeps it quiet. Cosmetic.
#572 dropped `MultiEdit`, `LS` and `NotebookRead` from `CLAUDE_DENY`, because current Claude Code warns at every start about a deny rule naming no known tool. A repository configured before that still lists all three, and re-running `sbx up` added the new entries without taking the old ones out, so those three warnings stayed until `sbx rm` then `sbx up`, or a hand edit. `sbx up` records what it added in `.sbx/agent-config.json` (op `item` on `permissions.deny`), so it can take back exactly the retired entries it wrote itself. Cortex mode already did this for the whole deny list; that code is now `dropDenies`, and the plain arm calls it with the retired names. One the developer wrote is not in the record, so it stays. Two details the issue leaves open: - The take-back runs after the additions, so `permissions.deny` is never empty at that point and `dropAt` cannot reach the emptied-container path. - A refused removal does not fail the run (`soft`). `dropAt`'s guards throw `ConfigConflict`, which would abort the whole `sbx up`; clearing a cosmetic warning is not worth failing a sandbox creation, so the entry and its record are left alone and `up` carries on. Cortex keeps the hard behaviour, where a kept deny would stop Claude Code loading CLAUDE.md. Tests: seven cases for the take-back (a re-run clearing the three and updating the record, a second run as a no-op, a hand-written entry kept, a list holding both a recorded and a hand-written copy, a record dropped for one already gone by hand, a dry run writing nothing, and `rm` still restoring the original file), plus one in the guard suite for the refused removal. Five mutations reintroduced and each shown to fail the suite. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Fixes #568.
What changed
1. The sandbox rules now reach the agent. Claude Code never loads the
CLAUDE.mdthatsbx upwrites: theReaddeny covers it, and an allow rule cannot carve an exception out of a deny. The rules now live once, assandboxRulesin@moca/sandbox-client, and are sent as the sandbox MCP server'sinstructions. Every MCP client receives those when it connects, whatever its permission rules.CLAUDE.md/AGENTS.mdblock is that same text under its heading. It comes out byte for byte as before, so existing repositories' blocks stay current.2. No more deny-name warnings.
CLAUDE_DENYdropsMultiEdit,LSandNotebookRead. Current Claude Code warns at every start about a deny rule naming no known tool, and those tools exist only before 2.0.MultiEdit*) don't warn, but they arrived in 2.1.166, after those tools were gone.sbx doctorinstead fails aclaude codecheck when theclaudeonPATHis older than 2.0.0. It runsclaude --version, and the check is listed only when it fails.3. A hole closed:
Monitor,PowerShellandLSPare now denied. ABashdeny does not coverMonitor. On 2.1.304, in a repository configured bysbx up, headless Claude rantouchon the laptop throughMonitor.OpenCode: 1.19.3 does not warn about unknown
toolskeys, soOPENCODE_OFFis unchanged.Spec §6.3 and §6.4 are updated to match.
Verification
@moca/sandbox-clientand@moca/mocactlvitest suites pass;make typecheckpasses; Prettier passes on every changed file.writeAgentConfigwrites:Monitoris no longer available;/workspacepersists"..mcp.jsonand in the smoke's--mcp-config .mcp.json --strict-mcp-configform. A smoke assertion on the rules is now possible; this PR doesn't add one.Not addressed
CLAUDE.mdexists andReadis denied. The notice is now harmless, since the rules arrive through the server.sbx upadds the new deny entries but does not removeMultiEdit,LSandNotebookRead.sbx rmfollowed bysbx up, or a hand edit, clears them.🤖 Assisted-By: Claude Code