|
| 1 | +--- |
| 2 | +title: Configuration |
| 3 | +pcx_content_type: navigation |
| 4 | +sidebar: |
| 5 | + order: 7 |
| 6 | +--- |
| 7 | + |
| 8 | +import { LinkTitleCard, CardGrid } from "~/components"; |
| 9 | + |
| 10 | +Configure your Sandbox SDK deployment with Wrangler, customize container images, and manage environment variables. |
| 11 | + |
| 12 | +<CardGrid> |
| 13 | + |
| 14 | +<LinkTitleCard |
| 15 | + title="Wrangler configuration" |
| 16 | + href="/sandbox/configuration/wrangler/" |
| 17 | + icon="document" |
| 18 | +> |
| 19 | + Configure Durable Objects bindings, container images, and Worker settings in wrangler.jsonc. |
| 20 | +</LinkTitleCard> |
| 21 | + |
| 22 | +<LinkTitleCard |
| 23 | + title="Dockerfile reference" |
| 24 | + href="/sandbox/configuration/dockerfile/" |
| 25 | + icon="wrench" |
| 26 | +> |
| 27 | + Customize the sandbox container image with your own packages, tools, and configurations. |
| 28 | +</LinkTitleCard> |
| 29 | + |
| 30 | +<LinkTitleCard |
| 31 | + title="Environment variables" |
| 32 | + href="/sandbox/configuration/environment-variables/" |
| 33 | + icon="gear" |
| 34 | +> |
| 35 | + Pass configuration and secrets to your sandboxes using environment variables. |
| 36 | +</LinkTitleCard> |
| 37 | + |
| 38 | +</CardGrid> |
| 39 | + |
| 40 | +## Quick reference |
| 41 | + |
| 42 | +### Essential wrangler.jsonc settings |
| 43 | + |
| 44 | +```jsonc |
| 45 | +{ |
| 46 | + "name": "my-worker", |
| 47 | + "main": "src/index.ts", |
| 48 | + "compatibility_date": "2024-09-02", |
| 49 | + "compatibility_flags": ["nodejs_compat"], |
| 50 | + "durable_objects": { |
| 51 | + "bindings": [ |
| 52 | + { |
| 53 | + "name": "Sandbox", |
| 54 | + "class_name": "Sandbox", |
| 55 | + "script_name": "@cloudflare/sandbox" |
| 56 | + } |
| 57 | + ] |
| 58 | + }, |
| 59 | + "containers": [ |
| 60 | + { |
| 61 | + "binding": "CONTAINER", |
| 62 | + "image": "ghcr.io/cloudflare/sandbox-runtime:latest" |
| 63 | + } |
| 64 | + ] |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### Common Dockerfile customizations |
| 69 | + |
| 70 | +```dockerfile |
| 71 | +FROM ghcr.io/cloudflare/sandbox-runtime:latest |
| 72 | + |
| 73 | +# Install additional Python packages |
| 74 | +RUN pip install scikit-learn tensorflow pandas |
| 75 | + |
| 76 | +# Install Node.js packages globally |
| 77 | +RUN npm install -g typescript ts-node |
| 78 | + |
| 79 | +# Install system packages |
| 80 | +RUN apt-get update && apt-get install -y postgresql-client |
| 81 | + |
| 82 | +# Add custom scripts |
| 83 | +COPY ./scripts /usr/local/bin/ |
| 84 | +``` |
| 85 | + |
| 86 | +### Environment variables |
| 87 | + |
| 88 | +```typescript |
| 89 | +// Pass to sandbox at creation |
| 90 | +const sandbox = getSandbox(env.Sandbox, 'my-sandbox'); |
| 91 | + |
| 92 | +// Configure environment for commands |
| 93 | +await sandbox.exec('node app.js', { |
| 94 | + env: { |
| 95 | + NODE_ENV: 'production', |
| 96 | + API_KEY: env.API_KEY, |
| 97 | + DATABASE_URL: env.DATABASE_URL |
| 98 | + } |
| 99 | +}); |
| 100 | +``` |
| 101 | + |
| 102 | +## Related resources |
| 103 | + |
| 104 | +- [Get Started guide](/sandbox/get-started/) - Initial setup walkthrough |
| 105 | +- [Wrangler documentation](/workers/wrangler/) - Complete Wrangler reference |
| 106 | +- [Docker documentation](https://docs.docker.com/engine/reference/builder/) - Dockerfile syntax |
| 107 | +- [Security model](/sandbox/concepts/security/) - Understanding environment isolation |
0 commit comments