Agent frameworks
Last updated: 5 December 2026 · @hadronbox/mcp 0.1.0 · API v1 (beta)
This page shows how an AI agent runs its commands and files in a hadronbox machine instead of on your computer. Each example gives the agent the MCP server; the agent creates a machine or reuses one, works in /workspace and pauses the machine when it is done.
All examples are in the examples/agents folder of the repository and run as they are. None of them contains a key: keys are read from environment variables.
Preparation
- Create a scoped key on the API keys page of the panel:
machines:create,machines:read,machines:exec,machines:manage. If the agent should not delete machines, leave outmachines:delete(scopes). - Set the key and your model provider's key as environment variables.
- Install Node.js 20 or later; the MCP server starts with
npx -y @hadronbox/mcp.
export HADRONBOX_API_KEY=...
export ANTHROPIC_API_KEY=... # OPENAI_API_KEY for OpenAI Agents
Claude Agent SDK (TypeScript)
The agent gets no local file or shell tools (tools: []); only the hadronbox tools are allowed. So every command runs in the machine.
import { query } from '@anthropic-ai/claude-agent-sdk';
for await (const message of query({
prompt: 'Create a machine, write hello.py, run it and pause the machine.',
options: {
model: 'claude-opus-5-5',
mcpServers: {
hadronbox: {
type: 'stdio',
command: 'npx',
args: ['-y', '@hadronbox/mcp'],
env: { HADRONBOX_API_KEY: process.env.HADRONBOX_API_KEY ?? '' },
},
},
allowedTools: [
'mcp__hadronbox__list_machines',
'mcp__hadronbox__create_machine',
'mcp__hadronbox__exec',
'mcp__hadronbox__read_file',
'mcp__hadronbox__write_file',
'mcp__hadronbox__pause_machine',
],
tools: [],
},
})) {
if (message.type === 'result' && message.subtype === 'success') process.stdout.write(`${message.result}\n`);
}
cd examples/agents/claude-agent-sdk-ts && npm install && npx tsx agent.ts "Run the tests of a new Node.js project"
Claude Agent SDK (Python)
import os
from claude_agent_sdk import ClaudeAgentOptions, query
options = ClaudeAgentOptions(
model="claude-opus-5-5",
mcp_servers={
"hadronbox": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@hadronbox/mcp"],
"env": {"HADRONBOX_API_KEY": os.environ["HADRONBOX_API_KEY"]},
}
},
allowed_tools=["mcp__hadronbox__exec", "mcp__hadronbox__write_file", "mcp__hadronbox__read_file"],
tools=[], # no local Bash/Read/Write
)
cd examples/agents/claude-agent-sdk-python && pip install -r requirements.txt && python agent.py
LangGraph
The tools are loaded with langchain-mcp-adapters and wired into a two-node graph (model, tools):
client = MultiServerMCPClient(
{
"hadronbox": {
"transport": "stdio",
"command": "npx",
"args": ["-y", "@hadronbox/mcp"],
"env": {"HADRONBOX_API_KEY": api_key, "PATH": os.environ.get("PATH", "")},
}
}
)
tools = await client.get_tools()
model = ChatAnthropic(model="claude-opus-5-5", max_tokens=16000).bind_tools(tools)
cd examples/agents/langgraph && pip install -r requirements.txt && python agent.py
OpenAI Agents
exec waits for the command to finish, so keep the session timeout long (the default of 5 seconds is too short):
async with MCPServerStdio(
name="hadronbox",
params={"command": "npx", "args": ["-y", "@hadronbox/mcp"], "env": {"HADRONBOX_API_KEY": api_key, "PATH": os.environ.get("PATH", "")}},
client_session_timeout_seconds=600, # exec can take up to 3600 s
) as hadronbox:
agent = Agent(name="sandbox-agent", instructions=INSTRUCTIONS, mcp_servers=[hadronbox])
result = await Runner.run(agent, task, max_turns=30)
cd examples/agents/openai-agents && pip install -r requirements.txt && python agent.py
Good practice
- Give the agent the narrowest key; you can revoke it when the work is done.
- The delete tool is off by default; if you need it, start the server with
--allow-deleteand addmachines:deleteto the key. - Running machines use credit (Credits and pricing). The system prompt in the examples asks the agent to pause the machine when it is done.
- The agent reads the hints in error results: for a missing scope, a blocked command (
COMMAND_BLOCKED) or too little credit (CREDIT_INSUFFICIENT) it tells you instead of retrying. Details: MCP server.