Skip to content

Commit 7d1976f

Browse files
Document Docker image variants and Python migration
Sync documentation for PR #259: Optimize Docker image size with lean and Python variants Changes: - Add documentation for two image variants (default and -python) - Include breaking change notice for Python users - Add migration guide from v0.5.x to v0.6.0+ - Document PYTHON_NOT_AVAILABLE error behavior - Update all examples to show appropriate image selection - Clarify Python availability requirements in Code Interpreter API Related upstream PR: cloudflare/sandbox-sdk#259
1 parent 4a2fab8 commit 7d1976f

File tree

3 files changed

+71
-10
lines changed

3 files changed

+71
-10
lines changed

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

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

1010
Execute Python, JavaScript, and TypeScript code with support for data visualizations, tables, and rich output formats. Contexts maintain state (variables, imports, functions) across executions.
1111

12+
:::note[Python execution requires Python image]
13+
To execute Python code, you must use the `-python` image variant in your Dockerfile:
14+
15+
```dockerfile
16+
FROM docker.io/cloudflare/sandbox:0.6.0-python
17+
```
18+
19+
The default image only supports JavaScript and TypeScript. Attempting to run Python code without the Python image will fail with a `PYTHON_NOT_AVAILABLE` error. See [Dockerfile reference](/sandbox/configuration/dockerfile/) for details on image variants.
20+
:::
21+
1222
## Methods
1323

1424
### `createCodeContext()`

src/content/docs/sandbox/concepts/containers.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ sidebar:
55
order: 3
66
---
77

8-
Each sandbox runs in an isolated Linux container with Python, Node.js, and common development tools pre-installed. For a complete list of pre-installed software and how to customize the container image, see [Dockerfile reference](/sandbox/configuration/dockerfile/).
8+
Each sandbox runs in an isolated Linux container with Node.js and common development tools pre-installed. Two image variants are available: a lean default image for shell and JavaScript workloads, and a Python-enabled image for data science tasks. For a complete list of pre-installed software and how to customize the container image, see [Dockerfile reference](/sandbox/configuration/dockerfile/).
99

1010
## Runtime software installation
1111

1212
Install additional software at runtime using standard package managers:
1313

1414
```bash
15-
# Python packages
15+
# Python packages (requires Python image variant)
1616
pip install scikit-learn tensorflow
1717

1818
# Node.js packages
@@ -22,6 +22,10 @@ npm install express
2222
apt-get update && apt-get install -y redis-server
2323
```
2424

25+
:::note[Python package installation]
26+
Python package installation requires the `-python` image variant. See [Dockerfile reference](/sandbox/configuration/dockerfile/) for details on choosing the appropriate image variant.
27+
:::
28+
2529
## Filesystem
2630

2731
The container provides a standard Linux filesystem. You can read and write anywhere you have permissions.

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

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,81 @@ 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: a lean image for shell and JavaScript workloads, and a Python-enabled image for data science and machine learning tasks.
13+
14+
### Image variants
15+
16+
**Default (lean)** - Shell 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.
22+
**Python variant** - Includes Python with data science packages (~1.3GB):
23+
24+
```dockerfile
25+
FROM docker.io/cloudflare/sandbox:0.3.3-python
26+
```
27+
28+
:::caution[Breaking change for Python users]
29+
**Version 0.6.0+ requires explicit Python image**
30+
31+
Starting with version 0.6.0, the default image no longer includes Python. If you use the [Code Interpreter API](/sandbox/api/interpreter/) to run Python code, you must use the `-python` image variant.
32+
33+
**Migration required:**
34+
35+
```dockerfile
36+
# Before (v0.5.x)
37+
FROM docker.io/cloudflare/sandbox:0.5.6
38+
39+
# After (v0.6.0+)
40+
FROM docker.io/cloudflare/sandbox:0.6.0-python
41+
```
42+
43+
Without this change, Python execution will fail with a `PYTHON_NOT_AVAILABLE` error.
44+
:::
45+
46+
:::note[Version synchronization required]
47+
Always match the Docker image version to your npm package version. If you are using `@cloudflare/sandbox@0.3.3`, use `docker.io/cloudflare/sandbox:0.3.3` (or `0.3.3-python`) as your base image.
2048

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.
49+
**Why this matters**: The SDK automatically checks version compatibility on startup. Mismatched versions can cause features to break or behave unexpectedly. If versions do not match, you will see warnings in your logs.
2250

2351
See [Version compatibility](/sandbox/concepts/sandboxes/#version-compatibility) for troubleshooting version mismatch warnings.
2452
:::
2553

26-
**What's included:**
54+
### What's included
55+
56+
**Default image includes:**
2757

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

63+
**Python image adds:**
64+
65+
- Python 3.11.14 with pip and venv
66+
- Pre-installed packages: matplotlib, numpy, pandas, ipython
67+
68+
### Choosing an image variant
69+
70+
Use the **default image** if you:
71+
- Only need shell command execution
72+
- Run JavaScript or TypeScript code
73+
- Want faster cold starts and smaller image size
74+
75+
Use the **Python image** if you:
76+
- Execute Python code via [Code Interpreter](/sandbox/api/interpreter/)
77+
- Need data science packages (numpy, pandas, matplotlib)
78+
- Require Python-specific functionality
79+
3580
## Creating a custom image
3681

3782
Create a `Dockerfile` in your project root:
3883

3984
```dockerfile title="Dockerfile"
40-
FROM docker.io/cloudflare/sandbox:0.3.3
85+
# Use Python variant if you need Python packages
86+
FROM docker.io/cloudflare/sandbox:0.3.3-python
4187

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

77123
```dockerfile title="Dockerfile"
124+
# Choose the appropriate base image for your needs
78125
FROM docker.io/cloudflare/sandbox:0.3.3
79126

80127
COPY my-app.js /workspace/my-app.js

0 commit comments

Comments
 (0)