claude-code-templates 1.24.1 → 1.24.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/sandbox/README.md +92 -10
- package/components/sandbox/cloudflare/.dev.vars.example +13 -0
- package/components/sandbox/cloudflare/IMPLEMENTATION_SUMMARY.md +359 -0
- package/components/sandbox/cloudflare/QUICKSTART.md +267 -0
- package/components/sandbox/cloudflare/README.md +301 -0
- package/components/sandbox/cloudflare/SANDBOX_DEBUGGING.md +442 -0
- package/components/sandbox/cloudflare/claude-code-sandbox.md +314 -0
- package/components/sandbox/cloudflare/launcher.ts +472 -0
- package/components/sandbox/cloudflare/monitor.ts +388 -0
- package/components/sandbox/cloudflare/package.json +54 -0
- package/components/sandbox/cloudflare/src/index.ts +240 -0
- package/components/sandbox/cloudflare/tsconfig.json +31 -0
- package/components/sandbox/cloudflare/wrangler.toml +50 -0
- package/package.json +2 -1
- package/src/index.js +241 -21
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# Cloudflare Sandbox Quick Start Guide
|
|
2
|
+
|
|
3
|
+
Get your Cloudflare Claude Code Sandbox running in under 5 minutes.
|
|
4
|
+
|
|
5
|
+
## Prerequisites Checklist
|
|
6
|
+
|
|
7
|
+
- [ ] Cloudflare account (sign up at https://dash.cloudflare.com/sign-up)
|
|
8
|
+
- [ ] Anthropic API key (get from https://console.anthropic.com/)
|
|
9
|
+
- [ ] Node.js 16.17.0+ installed
|
|
10
|
+
- [ ] Docker installed and running (for local development)
|
|
11
|
+
|
|
12
|
+
## Option 1: Deploy to Production (Fastest)
|
|
13
|
+
|
|
14
|
+
Perfect if you want to skip local testing and deploy directly.
|
|
15
|
+
|
|
16
|
+
### Step 1: Install Dependencies
|
|
17
|
+
```bash
|
|
18
|
+
cd .claude/sandbox/cloudflare
|
|
19
|
+
npm install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Step 2: Set API Key
|
|
23
|
+
```bash
|
|
24
|
+
npx wrangler secret put ANTHROPIC_API_KEY
|
|
25
|
+
# Paste your Anthropic API key when prompted
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Step 3: Deploy
|
|
29
|
+
```bash
|
|
30
|
+
npx wrangler deploy
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Step 4: Wait for Container Provisioning
|
|
34
|
+
```bash
|
|
35
|
+
# Wait 2-3 minutes, then check:
|
|
36
|
+
npx wrangler containers list
|
|
37
|
+
# You should see: ✓ Container ready
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Step 5: Test Your Deployment
|
|
41
|
+
```bash
|
|
42
|
+
# Get your worker URL from the deploy output, then:
|
|
43
|
+
curl -X POST https://YOUR-WORKER.YOUR-SUBDOMAIN.workers.dev/execute \
|
|
44
|
+
-H "Content-Type: application/json" \
|
|
45
|
+
-d '{"question": "What is the 10th Fibonacci number?"}'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Expected response:
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"success": true,
|
|
52
|
+
"question": "What is the 10th Fibonacci number?",
|
|
53
|
+
"code": "def fibonacci(n):\n ...",
|
|
54
|
+
"output": "55\n",
|
|
55
|
+
"error": "",
|
|
56
|
+
"executionTime": 1234
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Done!** Your sandbox is live at the edge.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Option 2: Local Development First
|
|
65
|
+
|
|
66
|
+
Perfect if you want to test locally before deploying.
|
|
67
|
+
|
|
68
|
+
### Step 1: Install Dependencies
|
|
69
|
+
```bash
|
|
70
|
+
cd .claude/sandbox/cloudflare
|
|
71
|
+
npm install
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Step 2: Create Local Environment File
|
|
75
|
+
```bash
|
|
76
|
+
cp .dev.vars.example .dev.vars
|
|
77
|
+
# Edit .dev.vars and add your Anthropic API key
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Step 3: Start Docker
|
|
81
|
+
```bash
|
|
82
|
+
# macOS: Open Docker Desktop
|
|
83
|
+
# Linux: sudo systemctl start docker
|
|
84
|
+
# Windows: Start Docker Desktop
|
|
85
|
+
|
|
86
|
+
# Verify Docker is running:
|
|
87
|
+
docker ps
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Step 4: Start Development Server
|
|
91
|
+
```bash
|
|
92
|
+
npm run dev
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Wait for:
|
|
96
|
+
```
|
|
97
|
+
⛅️ wrangler 3.78.12
|
|
98
|
+
-------------------
|
|
99
|
+
⎔ Starting local server...
|
|
100
|
+
[wrangler:inf] Ready on http://localhost:8787
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Step 5: Test Locally
|
|
104
|
+
```bash
|
|
105
|
+
# In a new terminal:
|
|
106
|
+
curl -X POST http://localhost:8787/execute \
|
|
107
|
+
-H "Content-Type: application/json" \
|
|
108
|
+
-d '{"question": "Calculate factorial of 5"}'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Step 6: Deploy When Ready
|
|
112
|
+
```bash
|
|
113
|
+
# Stop the dev server (Ctrl+C)
|
|
114
|
+
npx wrangler secret put ANTHROPIC_API_KEY
|
|
115
|
+
npx wrangler deploy
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Done!** You've tested locally and deployed.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Option 3: Using the CLI Tools
|
|
123
|
+
|
|
124
|
+
Perfect if you prefer command-line interaction.
|
|
125
|
+
|
|
126
|
+
### Step 1: Setup (same as above)
|
|
127
|
+
```bash
|
|
128
|
+
cd .claude/sandbox/cloudflare
|
|
129
|
+
npm install
|
|
130
|
+
npx wrangler secret put ANTHROPIC_API_KEY
|
|
131
|
+
npx wrangler deploy
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Step 2: Use the Launcher
|
|
135
|
+
```bash
|
|
136
|
+
# Execute a prompt
|
|
137
|
+
node launcher.ts "What is 2 to the power of 10?" \
|
|
138
|
+
"" \
|
|
139
|
+
your_anthropic_key \
|
|
140
|
+
https://your-worker.workers.dev
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Step 3: Use the Monitor (for debugging)
|
|
144
|
+
```bash
|
|
145
|
+
# Get detailed execution metrics
|
|
146
|
+
node monitor.ts "Calculate factorial of 5" \
|
|
147
|
+
your_anthropic_key \
|
|
148
|
+
https://your-worker.workers.dev
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Done!** You're using the CLI tools.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Common Issues & Quick Fixes
|
|
156
|
+
|
|
157
|
+
### "Container not ready"
|
|
158
|
+
**Solution**: Wait 2-3 minutes after first deployment
|
|
159
|
+
```bash
|
|
160
|
+
npx wrangler containers list
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### "Docker daemon is not running"
|
|
164
|
+
**Solution**: Start Docker Desktop or Docker service
|
|
165
|
+
```bash
|
|
166
|
+
docker ps # Should list containers
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### "ANTHROPIC_API_KEY not configured"
|
|
170
|
+
**Solution**: Set the secret
|
|
171
|
+
```bash
|
|
172
|
+
# Production:
|
|
173
|
+
npx wrangler secret put ANTHROPIC_API_KEY
|
|
174
|
+
|
|
175
|
+
# Local (.dev.vars):
|
|
176
|
+
echo "ANTHROPIC_API_KEY=sk-ant-your-key" > .dev.vars
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### "Worker not found"
|
|
180
|
+
**Solution**: Deploy the worker
|
|
181
|
+
```bash
|
|
182
|
+
npx wrangler deploy
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### "Execution timeout"
|
|
186
|
+
**Solution**: Increase timeout in request
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"question": "Your question",
|
|
190
|
+
"timeout": 60000
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Next Steps
|
|
197
|
+
|
|
198
|
+
### 1. Customize Your Worker
|
|
199
|
+
Edit `src/index.ts` to add custom logic:
|
|
200
|
+
- Add authentication
|
|
201
|
+
- Implement rate limiting
|
|
202
|
+
- Add custom error handling
|
|
203
|
+
- Create specialized endpoints
|
|
204
|
+
|
|
205
|
+
### 2. Add Monitoring
|
|
206
|
+
```bash
|
|
207
|
+
# Watch logs in real-time
|
|
208
|
+
npx wrangler tail
|
|
209
|
+
|
|
210
|
+
# Use the monitor tool
|
|
211
|
+
node monitor.ts "your prompt" your_api_key
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 3. Test Different Languages
|
|
215
|
+
```bash
|
|
216
|
+
# Python (default)
|
|
217
|
+
curl -X POST https://your-worker.workers.dev/execute \
|
|
218
|
+
-d '{"question": "Fibonacci", "language": "python"}'
|
|
219
|
+
|
|
220
|
+
# JavaScript
|
|
221
|
+
curl -X POST https://your-worker.workers.dev/execute \
|
|
222
|
+
-d '{"question": "Fibonacci", "language": "javascript"}'
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 4. Integrate with Your App
|
|
226
|
+
```javascript
|
|
227
|
+
// Frontend integration
|
|
228
|
+
const response = await fetch('https://your-worker.workers.dev/execute', {
|
|
229
|
+
method: 'POST',
|
|
230
|
+
headers: { 'Content-Type': 'application/json' },
|
|
231
|
+
body: JSON.stringify({ question: 'Calculate factorial of 5' })
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const result = await response.json();
|
|
235
|
+
console.log(result.output);
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 5. Enable Advanced Features
|
|
239
|
+
See the main [README.md](./README.md) for:
|
|
240
|
+
- Streaming output
|
|
241
|
+
- Code Interpreter API
|
|
242
|
+
- Caching strategies
|
|
243
|
+
- Performance optimization
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Resources
|
|
248
|
+
|
|
249
|
+
- **Documentation**: [README.md](./README.md)
|
|
250
|
+
- **Debugging**: [SANDBOX_DEBUGGING.md](./SANDBOX_DEBUGGING.md)
|
|
251
|
+
- **Component Info**: [claude-code-sandbox.md](./claude-code-sandbox.md)
|
|
252
|
+
- **Cloudflare Docs**: https://developers.cloudflare.com/sandbox/
|
|
253
|
+
- **Anthropic Docs**: https://docs.anthropic.com/
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Getting Help
|
|
258
|
+
|
|
259
|
+
1. **Check logs**: `npx wrangler tail`
|
|
260
|
+
2. **Use monitor**: `node monitor.ts "test" your_key`
|
|
261
|
+
3. **Read debugging guide**: [SANDBOX_DEBUGGING.md](./SANDBOX_DEBUGGING.md)
|
|
262
|
+
4. **Check container status**: `npx wrangler containers list`
|
|
263
|
+
5. **Test health**: `curl https://your-worker.workers.dev/health`
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
**You're all set! Start executing code with Claude AI on Cloudflare's edge network.**
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Cloudflare Claude Code Sandbox
|
|
2
|
+
|
|
3
|
+
Execute Claude Code in isolated Cloudflare Workers sandboxes with AI-powered code generation.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### 1. Install Dependencies
|
|
8
|
+
```bash
|
|
9
|
+
npm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### 2. Configure API Key
|
|
13
|
+
```bash
|
|
14
|
+
# For local development, create .dev.vars:
|
|
15
|
+
echo "ANTHROPIC_API_KEY=your-api-key-here" > .dev.vars
|
|
16
|
+
|
|
17
|
+
# For production, use wrangler secrets:
|
|
18
|
+
npx wrangler secret put ANTHROPIC_API_KEY
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 3. Local Development
|
|
22
|
+
```bash
|
|
23
|
+
# Start development server (requires Docker)
|
|
24
|
+
npm run dev
|
|
25
|
+
|
|
26
|
+
# In another terminal, test the endpoint:
|
|
27
|
+
curl -X POST http://localhost:8787/execute \
|
|
28
|
+
-H "Content-Type: application/json" \
|
|
29
|
+
-d '{"question": "What is the 10th Fibonacci number?"}'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 4. Deploy to Cloudflare
|
|
33
|
+
```bash
|
|
34
|
+
# Deploy worker
|
|
35
|
+
npx wrangler deploy
|
|
36
|
+
|
|
37
|
+
# Wait 2-3 minutes for container provisioning
|
|
38
|
+
npx wrangler containers list
|
|
39
|
+
|
|
40
|
+
# Test production endpoint
|
|
41
|
+
curl -X POST https://your-worker.your-subdomain.workers.dev/execute \
|
|
42
|
+
-H "Content-Type: application/json" \
|
|
43
|
+
-d '{"question": "Calculate factorial of 5"}'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Architecture
|
|
47
|
+
|
|
48
|
+
This sandbox combines three powerful technologies:
|
|
49
|
+
|
|
50
|
+
1. **Claude AI** (Anthropic) - Generates executable code from natural language
|
|
51
|
+
2. **Cloudflare Workers** - Runs at the edge for global low-latency access
|
|
52
|
+
3. **Sandbox SDK** - Provides isolated container execution
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
User Question → Cloudflare Worker → Claude AI → Generated Code → Sandbox → Results
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API Reference
|
|
59
|
+
|
|
60
|
+
### POST /execute
|
|
61
|
+
|
|
62
|
+
Execute a natural language question as code.
|
|
63
|
+
|
|
64
|
+
**Request:**
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"question": "What is the 100th Fibonacci number?",
|
|
68
|
+
"maxTokens": 2048, // Optional: Max tokens for code generation
|
|
69
|
+
"timeout": 30000, // Optional: Execution timeout in ms
|
|
70
|
+
"language": "python" // Optional: "python" or "javascript"
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Response:**
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"success": true,
|
|
78
|
+
"question": "What is the 100th Fibonacci number?",
|
|
79
|
+
"code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)\n\nprint(fibonacci(100))",
|
|
80
|
+
"output": "354224848179261915075\n",
|
|
81
|
+
"error": "",
|
|
82
|
+
"sandboxId": "user-1234567890-abc123",
|
|
83
|
+
"executionTime": 2147
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### GET /health
|
|
88
|
+
|
|
89
|
+
Check worker health status.
|
|
90
|
+
|
|
91
|
+
**Response:**
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"status": "healthy",
|
|
95
|
+
"timestamp": "2025-10-19T12:00:00.000Z",
|
|
96
|
+
"worker": "cloudflare-claude-sandbox"
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Command Line Tools
|
|
101
|
+
|
|
102
|
+
### Launcher
|
|
103
|
+
Execute prompts directly from command line:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Basic usage
|
|
107
|
+
node launcher.ts "Calculate factorial of 5"
|
|
108
|
+
|
|
109
|
+
# With custom worker URL
|
|
110
|
+
node launcher.ts "Fibonacci 10" "" your_api_key https://your-worker.workers.dev
|
|
111
|
+
|
|
112
|
+
# With components
|
|
113
|
+
node launcher.ts "Create a React app" "--agent frontend-developer" your_api_key
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Monitor
|
|
117
|
+
Monitor execution with detailed metrics:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Monitor execution
|
|
121
|
+
node monitor.ts "Calculate factorial of 5" your_api_key
|
|
122
|
+
|
|
123
|
+
# Monitor production worker
|
|
124
|
+
node monitor.ts "Sum array" your_api_key https://your-worker.workers.dev
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Examples
|
|
128
|
+
|
|
129
|
+
### Mathematical Calculations
|
|
130
|
+
```bash
|
|
131
|
+
curl -X POST http://localhost:8787/execute \
|
|
132
|
+
-H "Content-Type: application/json" \
|
|
133
|
+
-d '{"question": "What is the factorial of 20?"}'
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### String Manipulation
|
|
137
|
+
```bash
|
|
138
|
+
curl -X POST http://localhost:8787/execute \
|
|
139
|
+
-H "Content-Type: application/json" \
|
|
140
|
+
-d '{"question": "Reverse the string Hello World"}'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Data Analysis
|
|
144
|
+
```bash
|
|
145
|
+
curl -X POST http://localhost:8787/execute \
|
|
146
|
+
-H "Content-Type: application/json" \
|
|
147
|
+
-d '{"question": "Calculate the mean of [10, 20, 30, 40, 50]"}'
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### JavaScript Execution
|
|
151
|
+
```bash
|
|
152
|
+
curl -X POST http://localhost:8787/execute \
|
|
153
|
+
-H "Content-Type: application/json" \
|
|
154
|
+
-d '{
|
|
155
|
+
"question": "Sort an array of numbers",
|
|
156
|
+
"language": "javascript"
|
|
157
|
+
}'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Configuration
|
|
161
|
+
|
|
162
|
+
### Environment Variables
|
|
163
|
+
|
|
164
|
+
**Local Development (.dev.vars):**
|
|
165
|
+
```bash
|
|
166
|
+
ANTHROPIC_API_KEY=sk-ant-your-key-here
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Production (Wrangler Secrets):**
|
|
170
|
+
```bash
|
|
171
|
+
npx wrangler secret put ANTHROPIC_API_KEY
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Wrangler Configuration
|
|
175
|
+
|
|
176
|
+
Edit `wrangler.toml` to customize:
|
|
177
|
+
|
|
178
|
+
```toml
|
|
179
|
+
# Worker name (must be unique)
|
|
180
|
+
name = "my-custom-sandbox"
|
|
181
|
+
|
|
182
|
+
# Resource limits
|
|
183
|
+
[limits]
|
|
184
|
+
cpu_ms = 100 # CPU time per request
|
|
185
|
+
|
|
186
|
+
# Environment-specific configuration
|
|
187
|
+
[env.production]
|
|
188
|
+
vars = { ENVIRONMENT = "production" }
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Troubleshooting
|
|
192
|
+
|
|
193
|
+
### Container Not Ready
|
|
194
|
+
After first deployment, wait 2-3 minutes:
|
|
195
|
+
```bash
|
|
196
|
+
npx wrangler containers list
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Docker Issues (Local Development)
|
|
200
|
+
Ensure Docker is running:
|
|
201
|
+
```bash
|
|
202
|
+
docker ps
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### API Key Not Set
|
|
206
|
+
For local development:
|
|
207
|
+
```bash
|
|
208
|
+
echo "ANTHROPIC_API_KEY=your-key" > .dev.vars
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
For production:
|
|
212
|
+
```bash
|
|
213
|
+
npx wrangler secret put ANTHROPIC_API_KEY
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### View Logs
|
|
217
|
+
```bash
|
|
218
|
+
# Real-time logs
|
|
219
|
+
npx wrangler tail
|
|
220
|
+
|
|
221
|
+
# Pretty formatted
|
|
222
|
+
npx wrangler tail --format=pretty
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Performance Tips
|
|
226
|
+
|
|
227
|
+
1. **Use specific prompts**: More specific questions generate faster code
|
|
228
|
+
2. **Implement caching**: Cache generated code for common questions
|
|
229
|
+
3. **Stream output**: Use streaming for long-running operations
|
|
230
|
+
4. **Set appropriate timeouts**: Balance between UX and resource usage
|
|
231
|
+
5. **Monitor metrics**: Use the monitor tool to identify bottlenecks
|
|
232
|
+
|
|
233
|
+
## Security
|
|
234
|
+
|
|
235
|
+
- Sandboxes are isolated containers with no network access
|
|
236
|
+
- Code execution is limited by timeout (default 30s)
|
|
237
|
+
- CPU and memory limits are enforced by Cloudflare
|
|
238
|
+
- API keys are stored as encrypted Wrangler secrets
|
|
239
|
+
- CORS is enabled for browser access (configure as needed)
|
|
240
|
+
|
|
241
|
+
## Cost Estimation
|
|
242
|
+
|
|
243
|
+
**Cloudflare Workers:**
|
|
244
|
+
- Free tier: 100,000 requests/day (limited Durable Objects)
|
|
245
|
+
- Paid plan ($5/month): 10M requests/month + unlimited Durable Objects
|
|
246
|
+
|
|
247
|
+
**Anthropic API:**
|
|
248
|
+
- Claude Sonnet 4.5: ~$3 per million input tokens
|
|
249
|
+
- Average request: ~200 tokens = $0.0006 per request
|
|
250
|
+
|
|
251
|
+
**Example costs for 10,000 requests/month:**
|
|
252
|
+
- Cloudflare: $5/month (paid plan)
|
|
253
|
+
- Anthropic: ~$6/month (avg 200 tokens/request)
|
|
254
|
+
- **Total: ~$11/month**
|
|
255
|
+
|
|
256
|
+
## Development
|
|
257
|
+
|
|
258
|
+
### Project Structure
|
|
259
|
+
```
|
|
260
|
+
cloudflare-claude-sandbox/
|
|
261
|
+
├── src/
|
|
262
|
+
│ └── index.ts # Worker source code
|
|
263
|
+
├── launcher.ts # CLI launcher tool
|
|
264
|
+
├── monitor.ts # Monitoring tool
|
|
265
|
+
├── wrangler.toml # Cloudflare configuration
|
|
266
|
+
├── package.json # Dependencies
|
|
267
|
+
├── tsconfig.json # TypeScript config
|
|
268
|
+
└── README.md # This file
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Scripts
|
|
272
|
+
- `npm run dev` - Start local development server
|
|
273
|
+
- `npm run deploy` - Deploy to Cloudflare
|
|
274
|
+
- `npm run tail` - View real-time logs
|
|
275
|
+
- `npm run launch` - Run launcher tool
|
|
276
|
+
- `npm run monitor` - Run monitoring tool
|
|
277
|
+
- `npm run type-check` - Check TypeScript types
|
|
278
|
+
- `npm test` - Run tests
|
|
279
|
+
|
|
280
|
+
## Resources
|
|
281
|
+
|
|
282
|
+
- [Cloudflare Sandbox SDK](https://developers.cloudflare.com/sandbox/)
|
|
283
|
+
- [Cloudflare Workers Documentation](https://developers.cloudflare.com/workers/)
|
|
284
|
+
- [Anthropic API Documentation](https://docs.anthropic.com/)
|
|
285
|
+
- [Wrangler CLI Reference](https://developers.cloudflare.com/workers/wrangler/)
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
MIT License - See LICENSE file for details
|
|
290
|
+
|
|
291
|
+
## Support
|
|
292
|
+
|
|
293
|
+
For issues and questions:
|
|
294
|
+
1. Check the [debugging guide](./SANDBOX_DEBUGGING.md)
|
|
295
|
+
2. Run the monitor tool for detailed metrics
|
|
296
|
+
3. Check Cloudflare worker logs: `npx wrangler tail`
|
|
297
|
+
4. Open an issue on GitHub
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
Built with ❤️ using Cloudflare Workers, Claude AI, and the Sandbox SDK
|