Run Claude Code on a Sandbox
Build a Worker that takes a repository URL and a task description and uses Sandbox SDK to run Claude Code to implement your task.
Time to complete: 5 minutes
- Sign up for a Cloudflare account ↗.
 - Install 
Node.js↗. 
Node.js version manager
 Use a Node version manager like Volta ↗ or nvm ↗ to avoid permission issues and change Node.js versions. Wrangler, discussed later in this guide, requires a Node version of 16.17.0 or later.
You'll also need:
- An Anthropic API key ↗ for Claude Code
 - Docker ↗ running locally
 
Create a new Sandbox SDK project:
npm create cloudflare@latest -- claude-code-sandbox --template=cloudflare/sandbox-sdk/examples/claude-codeyarn create cloudflare claude-code-sandbox --template=cloudflare/sandbox-sdk/examples/claude-codepnpm create cloudflare@latest claude-code-sandbox --template=cloudflare/sandbox-sdk/examples/claude-codecd claude-code-sandboxCreate a .dev.vars file in your project root for local development:
echo "ANTHROPIC_API_KEY=your_api_key_here" > .dev.varsReplace your_api_key_here with your actual API key from the Anthropic Console ↗.
Start the development server:
npm run devTest with curl:
curl -X POST http://localhost:8787/ \  -d '{    "repo": "https://github.com/cloudflare/agents",    "task": "remove the emojis from the readme"  }'Response:
{  "logs": "Done! I've removed the brain emoji from the README title. The heading now reads \"# Cloudflare Agents\" instead of \"# 🧠 Cloudflare Agents\".",  "diff": "diff --git a/README.md b/README.md\nindex 9296ac9..027c218 100644\n--- a/README.md\n+++ b/README.md\n@@ -1,4 +1,4 @@\n-# 🧠 Cloudflare Agents\n+# Cloudflare Agents\n \n \n "}Deploy your Worker:
npx wrangler deployThen set your Anthropic API key as a production secret:
npx wrangler secret put ANTHROPIC_API_KEYPaste your API key from the Anthropic Console ↗ when prompted.
You created an API that:
- Accepts a repository URL and natural language task descriptions
 - Creates a Sandbox and clones the repository into it
 - Kicks off Claude Code to implement the given task
 - Returns Claude's output and changes
 
- Analyze data with AI - Add pandas and matplotlib for data analysis
 - Code Interpreter API - Use the built-in code interpreter instead of exec
 - Streaming output - Show real-time execution progress
 - API reference - Explore all available methods
 
- Anthropic Claude documentation ↗
 - Workers AI - Use Cloudflare's built-in models
 
Was this helpful?
- Resources
 - API
 - New to Cloudflare?
 - Directory
 - Sponsorships
 - Open Source
 
- Support
 - Help Center
 - System Status
 - Compliance
 - GDPR
 
- Company
 - cloudflare.com
 - Our team
 - Careers
 
- © 2025 Cloudflare, Inc.
 - Privacy Policy
 - Terms of Use
 - Report Security Issues
 - Trademark
 -