sandbox.commands.run as an in-process MCP tool so every command the agent generates runs in an isolated VM instead of on your machine.
Setup
ANTHROPIC_API_KEY from your local environment. Only the commands that the agent runs go to the sandbox.
Wire the sandbox into the agent
The highlighted block defines abash tool backed by the sandbox. Everything else is standard Claude Agent SDK usage.
allowedTools only skips the permission prompt; it does not remove Claude Code’s built-in Bash, Read, and Edit tools. Without tools: [], the agent can run commands on your machine instead of in the sandbox.
Add equivalent tools for file reads/writes the same way; see Run commands and Read & write files.