Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/sandbox/configuration.md
1# Configuration23## getSandbox Options45```typescript6const sandbox = getSandbox(env.Sandbox, 'sandbox-id', {7normalizeId: true, // lowercase ID (required for preview URLs)8sleepAfter: '10m', // sleep after inactivity: '5m', '1h', '2d' (default: '10m')9keepAlive: false, // false = auto-timeout, true = never sleep1011containerTimeouts: {12instanceGetTimeoutMS: 30000, // 30s for provisioning (default: 30000)13portReadyTimeoutMS: 90000 // 90s for container startup (default: 90000)14}15});16```1718**Sleep Config**:19- `sleepAfter`: Duration string (e.g., '5m', '10m', '1h') - default: '10m'20- `keepAlive: false`: Auto-sleep (default, cost-optimized)21- `keepAlive: true`: Never sleep (higher cost, requires explicit `destroy()`)22- Sleeping sandboxes wake automatically (cold start)2324## Instance Types2526wrangler.jsonc `instance_type`:27- `lite`: 256MB RAM, 0.5 vCPU (default)28- `standard`: 512MB RAM, 1 vCPU29- `heavy`: 1GB RAM, 2 vCPU3031## Dockerfile Patterns3233**Basic**:34```dockerfile35FROM docker.io/cloudflare/sandbox:0.7.036RUN pip3 install --no-cache-dir pandas numpy37EXPOSE 8080 # Required for wrangler dev38```3940**Scientific**:41```dockerfile42FROM docker.io/cloudflare/sandbox:0.7.043RUN pip3 install --no-cache-dir \44jupyter-server ipykernel matplotlib \45pandas seaborn plotly scipy scikit-learn46```4748**Node.js**:49```dockerfile50FROM docker.io/cloudflare/sandbox:0.7.051RUN npm install -g typescript ts-node52```5354**CRITICAL**: `EXPOSE` required for `wrangler dev` port access. Production auto-exposes all ports.5556## CLI Commands5758```bash59# Dev60wrangler dev # Start local dev server61wrangler deploy # Deploy to production62wrangler tail # Monitor logs63wrangler containers list # Check container status64wrangler secret put KEY # Set secret65```6667## Environment & Secrets6869**wrangler.jsonc**:70```jsonc71{72"vars": {73"ENVIRONMENT": "production",74"API_URL": "https://api.example.com"75},76"r2_buckets": [{77"binding": "DATA_BUCKET",78"bucket_name": "my-data-bucket"79}]80}81```8283**Usage**:84```typescript85const token = env.GITHUB_TOKEN; // From wrangler secret86await sandbox.exec('git clone ...', {87env: { GIT_TOKEN: token }88});89```9091## Preview URL Setup9293**Prerequisites**:94- Custom domain with wildcard DNS: `*.yourdomain.com → worker.yourdomain.com`95- `.workers.dev` domains NOT supported96- `normalizeId: true` in getSandbox97- `proxyToSandbox()` called first in fetch handler9899## Cron Triggers (Pre-warming)100101```jsonc102{103"triggers": {104"crons": ["*/5 * * * *"] // Every 5 minutes105}106}107```108109```typescript110export default {111async scheduled(event: ScheduledEvent, env: Env) {112const sandbox = getSandbox(env.Sandbox, 'main');113await sandbox.exec('echo "keepalive"'); // Wake sandbox114}115};116```117118## Logging Configuration119120**wrangler.jsonc**:121```jsonc122{123"vars": {124"SANDBOX_LOG_LEVEL": "debug", // debug | info | warn | error (default: info)125"SANDBOX_LOG_FORMAT": "pretty" // json | pretty (default: json)126}127}128```129130**Dev**: `debug` + `pretty`. **Production**: `info`/`warn` + `json`.131132## Timeout Environment Overrides133134Override default timeouts via environment variables:135136```jsonc137{138"vars": {139"SANDBOX_INSTANCE_TIMEOUT_MS": "60000", // Override instanceGetTimeoutMS140"SANDBOX_PORT_TIMEOUT_MS": "120000" // Override portReadyTimeoutMS141}142}143```144