Skip to content

Commit c0e3b8e

Browse files
committed
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>
1 parent 3f88a70 commit c0e3b8e

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

src/content/docs/sandbox/api/interpreter.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ if (result.error) {
104104
```
105105
</TypeScriptExample>
106106

107+
**Python not available**:
108+
109+
If you attempt to execute Python code without the Python image variant, you will receive a `PYTHON_NOT_AVAILABLE` error:
110+
111+
<TypeScriptExample>
112+
```
113+
try {
114+
const ctx = await sandbox.createCodeContext({ language: 'python' });
115+
} catch (error) {
116+
if (error.code === 'PYTHON_NOT_AVAILABLE') {
117+
// Update Dockerfile to use Python variant:
118+
// FROM docker.io/cloudflare/sandbox:0.5.6-python
119+
console.error('Python is not available in the default image');
120+
}
121+
}
122+
```
123+
</TypeScriptExample>
124+
125+
See [Dockerfile reference](/sandbox/configuration/dockerfile/) for migration instructions.
126+
107127
### `listCodeContexts()`
108128

109129
List all active code execution contexts.

src/content/docs/sandbox/configuration/dockerfile.mdx

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,57 @@ Customize the sandbox container image with your own packages, tools, and configu
99

1010
## Base image
1111

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):
1317

1418
```dockerfile
1519
FROM docker.io/cloudflare/sandbox:0.3.3
1620
```
1721

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.
24-
:::
25-
2622
**What's included:**
2723

2824
- Ubuntu 22.04 LTS base
29-
- Python 3.11.14 with pip and venv
3025
- Node.js 20 LTS with npm
3126
- Bun 1.x (JavaScript/TypeScript runtime)
32-
- Pre-installed Python packages: matplotlib, numpy, pandas, ipython
3327
- System utilities: curl, wget, git, jq, zip, unzip, file, procps, ca-certificates
3428

29+
### Python image
30+
31+
Full image with Python and data science packages (~1.3GB):
32+
33+
```dockerfile
34+
FROM docker.io/cloudflare/sandbox:0.3.3-python
35+
```
36+
37+
**What's included (in addition to default image):**
38+
39+
- Python 3.11.14 with pip and venv
40+
- Pre-installed Python packages: matplotlib, numpy, pandas, ipython
41+
42+
:::note[Choosing the right variant]
43+
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+
3556
## Creating a custom image
3657

3758
Create a `Dockerfile` in your project root:
3859

3960
```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
4163

4264
# Install additional Python packages
4365
RUN pip install --no-cache-dir \
@@ -75,6 +97,7 @@ When you run `wrangler dev` or `wrangler deploy`, Wrangler automatically builds
7597
Run services automatically when the container starts by creating a custom startup script:
7698

7799
```dockerfile title="Dockerfile"
100+
# Choose appropriate variant (default or -python)
78101
FROM docker.io/cloudflare/sandbox:0.3.3
79102

80103
COPY my-app.js /workspace/my-app.js
@@ -108,6 +131,19 @@ node /workspace/api-server.js &
108131
exec bun /container-server/dist/index.js
109132
```
110133

134+
## Migration guide
135+
136+
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+
111147
## Related resources
112148

113149
- [Image Management](/containers/platform-details/image-management/) - Building and pushing images to Cloudflare\'s registry

src/content/docs/sandbox/guides/code-execution.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import { TypeScriptExample } from "~/components";
1010

1111
This guide shows you how to execute Python and JavaScript code with rich outputs using the Code Interpreter API.
1212

13+
:::note[Python execution requires Python image variant]
14+
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+
1323
## When to use code interpreter
1424

1525
Use the Code Interpreter API for **simple, direct code execution** with minimal setup:

0 commit comments

Comments
 (0)