Agent module lets you start and manage Claude Agent SDK sessions that run inside the sandbox. The agent has full access to the sandbox filesystem and shell. Access it via sandbox.agent.
Starting an agent session
sandbox.agent.start(opts?)
Starts a new agent session inside the sandbox.
The task for the agent to perform.
Claude model to use (e.g.
"claude-sonnet-4-20250514").Custom system prompt for the agent.
List of tools the agent is allowed to use.
Permission mode for the agent session.
Maximum number of turns before the agent stops.
Working directory for the agent.
MCP servers to make available to the agent.
Callback for agent events (assistant messages, tool use, results, errors).
Callback for stderr output from the agent process.
Callback when the agent process exits.
Promise<AgentSession>
AgentSession
The object returned bysandbox.agent.start().
| Property / Method | Type | Description |
|---|---|---|
sessionId | string | Unique session identifier |
done | Promise<number> | Resolves with the exit code when the agent finishes |
sendPrompt(text) | (text: string) => void | Send a follow-up prompt to the agent |
interrupt() | () => void | Interrupt the agent’s current turn |
configure(config) | (config: AgentConfig) => void | Update agent configuration mid-session |
kill(signal?) | (signal?: number) => Promise<void> | Kill the agent process |
close() | () => void | Close the WebSocket connection |
Agent events
Events are delivered via theonEvent callback. Each event has a type field:
| Event type | Description |
|---|---|
ready | Agent process is ready |
configured | Configuration has been applied |
assistant | Assistant message (text output from the agent) |
tool_use_summary | Summary of a tool the agent used |
result | Final result from the agent |
turn_complete | A single turn has completed |
interrupted | Agent was interrupted |
error | An error occurred |