Skip to content

fix(sbx): steer agents through the MCP server's instructions; deny only known tools - #572

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/568-sbx-agent-steering
Oct 21, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/568-sbx-agent-steering

Conversation

@pdettori

@pdettori pdettori commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Fixes #568.

What changed

1. The sandbox rules now reach the agent. 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 rules now live once, as sandboxRules in @moca/sandbox-client, and are sent as the sandbox MCP server's instructions. Every MCP client receives those when it connects, whatever its permission rules.

  • The CLAUDE.md/AGENTS.md block 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_DENY drops MultiEdit, LS and NotebookRead. Current Claude Code warns at every start about a deny rule naming no known tool, and those tools exist only before 2.0.

  • No silent form covers them. Tool-name globs (MultiEdit*) don't warn, but they arrived in 2.1.166, after those tools were gone.
  • sbx doctor instead fails a claude code check when the claude on PATH is older than 2.0.0. It runs claude --version, and the check is listed only when it fails.

3. A hole closed: Monitor, PowerShell and LSP are now denied. A Bash deny does not cover Monitor. On 2.1.304, in a repository configured by sbx up, headless Claude ran touch on the laptop through Monitor.

OpenCode: 1.19.3 does not warn about unknown tools keys, so OPENCODE_OFF is unchanged.

Spec §6.3 and §6.4 are updated to match.

Verification

  • @moca/sandbox-client and @moca/mocactl vitest suites pass; make typecheck passes; Prettier passes on every changed file.
  • Headless Claude Code 2.1.304, with the real MCP server (fake exec) and the settings writeAgentConfig writes:
    • no deny-name warnings;
    • Monitor is no longer available;
    • asked only about its instructions, the agent answered "fresh VM, no process carries over", "no network", and "only /workspace persists".
    • It did so both through the project .mcp.json and in the smoke's --mcp-config .mcp.json --strict-mcp-config form. A smoke assertion on the rules is now possible; this PR doesn't add one.

Not addressed

  • Interactive sessions still show "Instruction file not loaded". CLAUDE.md exists and Read is denied. The notice is now harmless, since the rules arrive through the server.
  • Repositories already bound keep the three warnings until reconfigured. Re-running sbx up adds the new deny entries but does not remove MultiEdit, LS and NotebookRead. sbx rm followed by sbx up, or a hand edit, clears them.

🤖 Assisted-By: Claude Code

…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]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 21, 2026

@ingpaolodettori-dev ingpaolodettori-dev 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.

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 new claude code row is missing, so a user who hits it has no troubleshooting entry. One row would do: "Claude Code older than 2.0.0, whose MultiEdit/LS/NotebookRead act 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 up records what it added in its manifest, so it could remove exactly the MultiEdit/LS/NotebookRead deny entries it wrote earlier and leave any the developer added by hand. That would clear the warnings without sbx rm + sbx up. Fine as a follow-up issue.
  • Two nits inline.

Comment thread packages/mocactl/src/sbx/doctor.ts Outdated
/** `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'], {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/mocactl/src/sbx/doctor.ts Outdated
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',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@pdettori

Copy link
Copy Markdown
Member Author

Thanks for the review. Pushed 692bd90:

The mocactl suite and typecheck pass.

@ingpaolodettori-dev ingpaolodettori-dev 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.

Follow-up at 692bd90: everything from our 22875f4 review is addressed. The probe is async with a win32 shell, the detail wording is fixed, the user-guide §8 claude code row is added, and bound-repo cleanup is tracked in #574. CI is green. One cosmetic nit inline.

const { stdout } = await execFileAsync('claude', ['--version'], {
encoding: 'utf8',
timeout: 10_000,
shell: process.platform === 'win32',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pdettori
pdettori merged commit fa766ae into rossoctl:main Oct 21, 2026
15 checks passed
@pdettori
pdettori deleted the fix/568-sbx-agent-steering branch October 21, 2026 20:16
cwiklik added a commit that referenced this pull request Oct 27, 2026
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sbx up's agent config: the CLAUDE.md steering never loads (Read deny), and stale deny names warn on every startup

2 participants