davila7/claude-code-templates / cli-tool/components/skills/development/cloudflare-deploy
cloudflare-deploy
FlaggedDeploy applications and infrastructure to Cloudflare using Workers, Pages, and related platform services. Use when the user asks to deploy, host, publish, or set up a project on Cloudflare.
references/sandbox/api.md
View on GitHub# API Reference
## Command Execution
```typescript
// Basic
const result = await sandbox.exec('python3 script.py');
// Returns: { stdout, stderr, exitCode, success, duration }
// With options
await sandbox.exec('python3 test.py', {
cwd: '/workspace/project',
env: { API_KEY: 'secret' },
stream: true,
onOutput: (stream, data) => console.log(data)
});
```
## File Operations
```typescript
// Read/Write
const { content } = await sandbox.readFile('/workspace/data.txt');
await sandbox.writeFile('/workspace/file.txt', 'content'); // Auto-creates dirs
// List/Delete
const files = await sandbox.listFiles('/workspace');
await sandbox.deleteFile('/workspace/temp.txt');
await sandbox.deleteFile('/workspace/dir', { recursive: true });
// Utils
await sandbox.mkdir('/workspace/dir', { recursive: true });
await sandbox.pathExists('/workspace/file.txt');
```
## Background Processes
```typescript
// Start
const process = await sandbox.startProcess('python3 -m http.server 8080', {
processId: 'web-server',
cwd: '/workspace/public',
env: { PORT: '8080' }
});
// Returns: { id, pid, command }
// Wait for readiness
await process.waitForPort(8080); // Wait for port to listen
await process.waitForLog(/Server running/); // Wait for log pattern
await process.waitForExit(); // Wait for completion
// Management
const processes = await sandbox.listProcesses();
const info = await sandbox.getProcess('web-server');
await sandbox.stopProcess('web-server');
const logs = await sandbox.getProcessLogs('web-server');
```
## Port Exposure
```typescript
// Expose port
const { url } = await sandbox.exposePort(8080, {
name: 'web-app',
hostname: request.hostname
});
// Management
await sandbox.isPortExposed(8080);
await sandbox.getExposedPorts(request.hostname);
await sandbox.unexposePort(8080);
```
## Sessions (Isolated Contexts)
Each session maintains own shell state, env vars, cwd, process namespace.
```typescript
// Create with context
const session = await sandbox.createSession({
id: 'user-123',
cwd: '/workspace/user123',
env: { USER_ID: '123' }
});
// Use (full sandbox API)
await session.exec('echo $USER_ID');
await session.writeFile('config.txt', 'data');
// Manage
await sandbox.getSession('user-123');
await sandbox.deleteSession('user-123');
```
## Code Interpreter
```typescript
// Create context with variables
const ctx = await sandbox.createCodeContext({
language: 'python',
variables: {
data: [1, 2, 3, 4, 5],
config: { verbose: true }
}
});
// Execute code with rich outputs
const result = await ctx.runCode(`
import matplotlib.pyplot as plt
plt.plot(data, [x**2 for x in data])
plt.savefig('plot.png')
print(f"Processed {len(data)} points")
`);
// Returns: { outputs: [{ type: 'text'|'image'|'html', content }], error }
// Context persists variables across runs
const result2 = await ctx.runCode('print(data[0])'); // Still has 'data'
```
## WebSocket Connections
```typescript
// Proxy WebSocket to sandbox service
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const proxyResponse = await proxyToSandbox(request, env);
if (proxyResponse) return proxyResponse;
if (request.headers.get('Upgrade')?.toLowerCase() === 'websocket') {
const sandbox = getSandbox(env.Sandbox, 'realtime');
return await sandbox.wsConnect(request, 8080);
}
return new Response('Not a WebSocket request', { status: 400 });
}
};
```
## Bucket Mounting (S3 Storage)
```typescript
// Mount R2 bucket (production only, not wrangler dev)
await sandbox.mountBucket(env.DATA_BUCKET, '/data', {
readOnly: false
});
// Access files in mounted bucket
await sandbox.exec('ls /data');
await sandbox.writeFile('/data/output.txt', 'result');
// Unmount
await sandbox.unmountBucket('/data');
```
**Note**: Bucket mounting only works in production. Mounted buckets are sandbox-scoped (visible to all sessions in that sandbox).
## Lifecycle Management
```typescript
// Terminate container immediately
await sandbox.destroy();
// REQUIRED when using keepAlive: true
const sandbox = getSandbox(env.Sandbox, 'temp', { keepAlive: true });
try {
await sandbox.writeFile('/tmp/code.py', code);
const result = await sandbox.exec('python /tmp/code.py');
return result.stdout;
} finally {
await sandbox.destroy(); // Free resources
}
```
Deletes: files, processes, sessions, network connections, exposed ports.
## Error Handling
```typescript
// Command errors
const result = await sandbox.exec('python3 invalid.py');
if (!result.success) {
console.error('Exit code:', result.exitCode);
console.error('Stderr:', result.stderr);
}
// SDK errors
try {
await sandbox.readFile('/nonexistent');
} catch (error) {
if (error.code === 'FILE_NOT_FOUND') { /* ... */ }
else if (error.code === 'CONTAINER_NOT_READY') { /* retry */ }
else if (error.code === 'TIMEOUT') { /* ... */ }
}
// Retry pattern (see gotchas.md for full implementation)
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |