apps/docs/src/content/docs/en/guides/claude/claude-agent-sdk-connect-service-sandbox.mdx
This guide demonstrates how to run a two-agent autonomous coding system using the Claude Agent SDK and Daytona sandboxes. The system consists of a Project Manager Agent (local) and a Developer Agent (in-sandbox), enabling advanced delegation, planning, and secure code execution.
The Project Manager Agent runs locally and uses the basic Anthropic interface with the claude-sonnet-4-20250514 model for high-level planning and task delegation. The Developer Agent runs inside the Daytona sandbox and is created using the Claude Agent SDK, which leverages Claude Code for advanced coding and automation capabilities. This architecture separates high-level planning from low-level code execution for more robust automation.
A key advantage of this approach is its extensibility: you can easily replace the Project Manager Agent with your own custom orchestrator logic, or even another agent, making the system highly reusable and adaptable to a wide range of advanced automation and coordination use cases.
When the main module is launched, a Daytona sandbox is created for the Developer Agent, and a Project Manager Agent is initialized locally. Interaction with the system occurs via a command line chat interface. The Project Manager Agent receives prompts, plans the workflow, and delegates coding tasks to the Developer Agent. The Developer Agent executes tasks in the sandbox and streams results back to the Project Manager, who reviews and coordinates further actions. All logs and outputs from both agents are streamed in real time to the terminal, providing full visibility into the process as it is managed by the Project Manager Agent.
The Developer Agent can also host web apps and provide preview links using Daytona Preview Links. The Project Manager Agent will present these links and summarize the results for you.
You can continue interacting with the system until you are finished. When you exit the program, the sandbox is deleted automatically.
First, clone the daytona repository and navigate to the example directory:
git clone https://github.com/daytonaio/daytona.git
cd daytona/guides/typescript/anthropic/multi-agent-claude-sdk
To run this example, you need to set the following environment variables:
DAYTONA_API_KEY: Required for access to Daytona sandboxes. Get it from Daytona DashboardANTHROPIC_API_KEY: Required for the Project Manager Agent (runs locally). Get it from Claude Developer PlatformSANDBOX_ANTHROPIC_API_KEY: Optional for the Developer Agent (runs in sandbox). If not provided, defaults to using ANTHROPIC_API_KEY. Get it from Claude Developer PlatformCopy .env.example to .env and add your keys:
DAYTONA_API_KEY=your_daytona_key
ANTHROPIC_API_KEY=your_anthropic_key
SANDBOX_ANTHROPIC_API_KEY=your_anthropic_key
:::tip[Agent API Key Options]
You can use a single ANTHROPIC_API_KEY for both agents, or provide a separate SANDBOX_ANTHROPIC_API_KEY for billing/tracking purposes.
:::
:::caution[API Key Security]
The SANDBOX_ANTHROPIC_API_KEY is passed into the Daytona sandbox environment and is accessible to any code executed inside the sandbox.
:::
:::note[Node.js Version] Node.js 18 or newer is required to run this example. Please ensure your environment meets this requirement before proceeding. :::
Install dependencies:
npm install
Run the two-agent system:
npm run start
The system will start and wait for your prompt.
Example chat session:
$ npm run start
Creating Developer Agent sandbox...
Installing Developer Agent SDK...
Initializing Developer Agent...
Initializing Project Manager Agent...
=== Two-Agent System Ready ===
Project Manager Agent: Manages tasks and delegates to Developer (Green text)
Developer Agent: Executes code in Daytona sandbox (White text)
Press Ctrl+C at any time to exit.
User: make a lunar lander web app
[Project Manager] Processing your request...
[Project Manager]: I'll help you create a lunar lander web app! Let me delegate this task to the Developer Agent.
<developer_task>
Create a lunar lander web game with the following features:
- HTML/CSS/JavaScript based
- Canvas graphics for the game
- Physics simulation (gravity, thrust, velocity)
- Keyboard controls (arrow keys)
- Landing detection (safe landing vs crash)
- Fuel management system
- Start the game on port 80 and provide the preview URL
</developer_task>
[Delegating to Developer Agent]...
I'll help you create a lunar lander web app! Let me build a complete game with physics simulation, graphics, and controls.
šØ Write
šØ Write
šØ Bash
Perfect! The web server is now running.
Your Lunar Lander game is live at:
š https://80-17ac1c0f-d684-4122-93b5-8f52fd5393f8.proxy.daytona.works
[Project Manager]: Excellent! The Developer Agent has successfully created your lunar lander web app. The game is now running and accessible at the preview URL above. The implementation includes:
ā Physics simulation with gravity and thrust
ā Canvas-based graphics
ā Keyboard controls for gameplay
ā Landing detection system
ā Fuel management
ā Web server running on port 80
TASK_COMPLETE
[Project Manager] All tasks completed!
This system is composed of two collaborating agents, each with a distinct role and implementation. Below is a step-by-step guide to how each agent operates and interacts within the workflow.
<developer_task> tags in its response.TASK_COMPLETE, which signals the system to terminate the session.pip install (see process execution).import coding_agent).<developer_task> is received, the system sends the task to the Developer Agent by running a Python command in the interpreter context:
const result = await sandbox.codeInterpreter.runCode(
`coding_agent.run_query_sync(os.environ.get('PROMPT', ''))`,
{
context: ctx,
envs: { PROMPT: task },
onStdout,
onStderr,
}
);
You can customize the Project Manager Agent's behavior by modifying the system prompt in src/index.ts. The current implementation:
<developer_task> tags for delegationWhen you exit the main program, the Daytona sandbox and all files are automatically deleted.
Key advantages: