Skip to main content
An agent session is a Claude Agent SDK instance running inside a sandbox. You send a prompt, the agent works autonomously — writing files, running commands, iterating on errors — and streams events back to your code.
import { Sandbox } from "@opencomputer/sdk";

const sandbox = await Sandbox.create();
const session = await sandbox.agent.start({
  prompt: "Create a Next.js app with a landing page",
  onEvent: (event) => console.log(`[${event.type}]`, event),
});

const exitCode = await session.done;
await sandbox.kill();

How It Works

The SDK spawns the Claude Agent SDK inside the sandbox VM as a regular process. Claude gets bash and file tools, then works in a think → act → observe loop. Events stream back to your code over WebSocket as JSON lines. The agent has full access to the sandbox filesystem, network, and shell — the same environment you’d get with sandbox.exec or oc shell.

Starting an Agent

sandbox.agent.start() creates an agent session and returns immediately. Events arrive via callbacks.

Parameters

ParameterTypeDescription
promptstringInitial prompt for the agent
modelstringClaude model (default: claude-sonnet-4-20250514)
systemPromptstringSystem prompt
allowedToolsstring[]Restrict which tools the agent can use
permissionModestringPermission mode for tool use
maxTurnsnumberMaximum conversation turns (default: 50)
cwdstringWorking directory inside the sandbox
mcpServersobjectMCP server configuration (see Tools)
onEventcallbackCalled for each event
onErrorcallbackCalled on error
TypeScript only:
ParameterTypeDescription
resumestringResume a previous session by ID
onExitcallbackCalled when agent process exits
onScrollbackEndcallbackCalled when scrollback replay completes
Python uses snake_case: system_prompt, allowed_tools, permission_mode, max_turns, mcp_servers, on_event, on_error.

AgentSession

The returned session object lets you interact with the running agent.
MethodTypeScriptPythonDescription
Send follow-upsendPrompt(text)send_prompt(text)Send a follow-up prompt
Wait for completionawait session.doneawait session.wait()Returns exit code
Collect all eventsawait session.collect_events()Collect events until exit
Interruptsession.interrupt()session.interrupt()Stop the current turn
Reconfiguresession.configure(opts)session.configure(...)Update model, tools, cwd
Killawait session.kill()await session.kill()Terminate the process (SIGKILL)
Closesession.close()await session.close()Close WebSocket connection
PropertyTypeScriptPython
Session IDsession.sessionIdsession.session_id

Attaching to an Existing Session

Reconnect to a running agent session to resume receiving events:
const session = await sandbox.agent.attach(sessionId, {
  onEvent: (event) => console.log(event),
});

Listing Sessions

const sessions = await sandbox.agent.list();
// [{ sessionID, sandboxID, running, startedAt }]
Full reference: TypeScript SDK · Python SDK · HTTP API.