You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document Docker image variants and Python migration
Sync documentation for PR #259 which introduces lean and Python image variants:
- Add documentation for two image variants (default lean vs -python)
- Document migration guide for Python users upgrading from <0.5.6
- Add PYTHON_NOT_AVAILABLE error handling examples
- Update all Dockerfile examples to show appropriate variant usage
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/configuration/dockerfile.mdx
+48-12Lines changed: 48 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,35 +9,57 @@ Customize the sandbox container image with your own packages, tools, and configu
9
9
10
10
## Base image
11
11
12
-
The Sandbox SDK uses a Ubuntu-based Linux container with Python, Node.js (via Bun), and common development tools pre-installed:
12
+
The Sandbox SDK provides two image variants optimized for different use cases:
13
+
14
+
### Default (lean) image
15
+
16
+
Optimized for shell commands and JavaScript/TypeScript execution (~600-800MB):
13
17
14
18
```dockerfile
15
19
FROM docker.io/cloudflare/sandbox:0.3.3
16
20
```
17
21
18
-
:::caution[Version synchronization required]
19
-
Always match the Docker image version to your npm package version. If you're using `@cloudflare/sandbox@0.3.3`, use `docker.io/cloudflare/sandbox:0.3.3` as your base image.
20
-
21
-
**Why this matters**: The SDK automatically checks version compatibility on startup. Mismatched versions can cause features to break or behave unexpectedly. If versions don't match, you'll see warnings in your logs.
22
-
23
-
See [Version compatibility](/sandbox/concepts/sandboxes/#version-compatibility) for troubleshooting version mismatch warnings.
Use the default (lean) image for shell operations, JavaScript/TypeScript execution, and Git workflows. Only use the `-python` variant if you need Python code execution with [`CodeInterpreter.runCode()`](/sandbox/api/interpreter/).
44
+
45
+
Using the lean image reduces image size by ~500MB and improves cold start times.
46
+
:::
47
+
48
+
:::caution[Version synchronization required]
49
+
Always match the Docker image version to your npm package version. If you're using `@cloudflare/sandbox@0.3.3`, use `docker.io/cloudflare/sandbox:0.3.3` (or `0.3.3-python`) as your base image.
50
+
51
+
**Why this matters**: The SDK automatically checks version compatibility on startup. Mismatched versions can cause features to break or behave unexpectedly. If versions don't match, you'll see warnings in your logs.
52
+
53
+
See [Version compatibility](/sandbox/concepts/sandboxes/#version-compatibility) for troubleshooting version mismatch warnings.
54
+
:::
55
+
35
56
## Creating a custom image
36
57
37
58
Create a `Dockerfile` in your project root:
38
59
39
60
```dockerfile title="Dockerfile"
40
-
FROM docker.io/cloudflare/sandbox:0.3.3
61
+
# Use Python variant if you need Python packages
62
+
FROM docker.io/cloudflare/sandbox:0.3.3-python
41
63
42
64
# Install additional Python packages
43
65
RUN pip install --no-cache-dir \
@@ -75,6 +97,7 @@ When you run `wrangler dev` or `wrangler deploy`, Wrangler automatically builds
75
97
Run services automatically when the container starts by creating a custom startup script:
If you are upgrading from a version prior to 0.5.6 and use Python code execution, update your Dockerfile to use the `-python` variant:
137
+
138
+
```diff title="Dockerfile"
139
+
- FROM docker.io/cloudflare/sandbox:0.5.5
140
+
+ FROM docker.io/cloudflare/sandbox:0.5.6-python
141
+
```
142
+
143
+
**Why this change was made**: Separating Python into its own image variant reduces the default image size by ~500MB, improving cold start times for workloads that do not require Python.
144
+
145
+
If you attempt to execute Python code without the `-python` variant, you will receive a `PYTHON_NOT_AVAILABLE` error with instructions to update your Dockerfile.
146
+
111
147
## Related resources
112
148
113
149
-[Image Management](/containers/platform-details/image-management/) - Building and pushing images to Cloudflare\'s registry
To execute Python code, your Dockerfile must use the `-python` image variant:
15
+
16
+
```dockerfile
17
+
FROM docker.io/cloudflare/sandbox:0.5.6-python
18
+
```
19
+
20
+
The default (lean) image does not include Python. If you attempt Python execution without the Python variant, you will receive a `PYTHON_NOT_AVAILABLE` error. See [Dockerfile reference](/sandbox/configuration/dockerfile/) for details.
21
+
:::
22
+
13
23
## When to use code interpreter
14
24
15
25
Use the Code Interpreter API for **simple, direct code execution** with minimal setup:
0 commit comments