Skip to content

Commit 22a5670

Browse files
Cleanup sandbox docs (#25944)
* Improve sandbox getting started links * Add descriptions to sandbox tutorials * Fix tutorials * Cross-reference commands & processes better * Fix the architecture diagram * Clarify persistence information * Update pre-installed software * Document preview URL setup * Clarify preview url usage * Fix sandbox configuration information
1 parent 13b163f commit 22a5670

30 files changed

+842
-803
lines changed

src/content/docs/containers/get-started.mdx

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

8-
import { WranglerConfig, PackageManagers } from "~/components";
8+
import { Render, PackageManagers, WranglerConfig } from "~/components";
99

1010
In this guide, you will deploy a Worker that can make requests to one or more Containers in response to end-user requests.
1111
In this example, each container runs a small webserver written in Go.
@@ -17,10 +17,9 @@ This example Worker should give you a sense for simple Container use, and provid
1717
### Ensure Docker is running locally
1818

1919
In this guide, we will build and push a container image alongside your Worker code. By default, this process uses
20-
[Docker](https://www.docker.com/) to do so. You must have Docker running locally when you run `wrangler deploy`. For most people, the best way to install Docker is to follow the [docs for installing Docker Desktop](https://docs.docker.com/desktop/). Other tools like [Colima](https://github.com/abiosoft/colima) may also work.
20+
[Docker](https://www.docker.com/) to do so.
2121

22-
You can check that Docker is running properly by running the `docker info` command in your terminal. If Docker is running, the command will succeed. If Docker is not running,
23-
the `docker info` command will hang or return an error including the message "Cannot connect to the Docker daemon".
22+
<Render product="containers" file="docker-setup" />
2423

2524
{/* FUTURE CHANGE: Add some image you can use if you don't have Docker running. */}
2625
{/* FUTURE CHANGE: Link to docs on alternative build/push options */}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getSandbox } from '@cloudflare/sandbox';
1717
const sandbox = getSandbox(env.Sandbox, 'user-123');
1818
```
1919

20-
The sandbox ID should be unique per user or session. The same ID will always return the same sandbox instance with persistent state.
20+
The same sandbox ID will always return the same sandbox instance. You can architect your application to use a single sandbox ID for multiple users, or use unique IDs per user or session. Using unique sandbox IDs per user is recommended if you are providing code generation or execution capabilities directly to your users.
2121

2222
## API organization
2323

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ sidebar:
77

88
import { TypeScriptExample } from "~/components";
99

10+
:::note[Production requires custom domain]
11+
Preview URLs require a custom domain with wildcard DNS routing in production. See [Production Deployment](/sandbox/guides/production-deployment/).
12+
:::
13+
1014
Expose services running in your sandbox via public preview URLs. See [Preview URLs concept](/sandbox/concepts/preview-urls/) for details.
1115

1216
## Methods
@@ -32,7 +36,7 @@ await sandbox.startProcess('python -m http.server 8000');
3236
const exposed = await sandbox.exposePort(8000);
3337
3438
console.log('Available at:', exposed.exposedAt);
35-
// https://abc123-8000.sandbox.workers.dev
39+
// https://8000-abc123.example.com
3640
3741
// Multiple services with names
3842
await sandbox.startProcess('node api.js');

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

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,37 @@ sidebar:
55
order: 1
66
---
77

8-
The Sandbox SDK provides isolated code execution environments on Cloudflare's edge network. It combines three Cloudflare technologies:
8+
Sandbox SDK lets you execute untrusted code safely from your Workers. It combines three Cloudflare technologies to provide secure, stateful, and isolated execution:
99

10-
- **Workers** - JavaScript runtime at the edge
11-
- **Durable Objects** - Stateful compute with persistent storage
12-
- **Containers** - Isolated execution environments with full Linux capabilities
10+
- **Workers** - Your application logic that calls the Sandbox SDK
11+
- **Durable Objects** - Persistent sandbox instances with unique identities
12+
- **Containers** - Isolated Linux environments where code actually runs
1313

14-
## Three-layer architecture
14+
## Architecture overview
1515

16-
```
17-
┌─────────────────────────────────────────────────────────┐
18-
│ Your Application │
19-
│ (Cloudflare Worker) │
20-
└───────────────────────────┬─────────────────────────────┘
21-
├─ getSandbox()
22-
├─ exec()
23-
├─ writeFile()
24-
25-
┌────────────────▼──────────────────┐
26-
│ Container-enabled Durable Object │
27-
│ (SDK methods via RPC from Worker) │
28-
└───────────────────────────────────┘
29-
│ HTTP/JSON
30-
31-
┌───────▼───────┐
32-
│ Durable Object │ Layer 2: State Management
33-
│ (Persistent) │
34-
└───────┬───────┘
35-
│ Container Protocol
36-
37-
┌───────▼───────┐
38-
│ Container │ Layer 3: Isolated Execution
39-
│ (Linux + Bun) │
40-
└───────────────┘
16+
```mermaid
17+
flowchart TB
18+
accTitle: Sandbox SDK Architecture
19+
accDescr: Three-layer architecture showing how Cloudflare Sandbox SDK combines Workers, Durable Objects, and Containers for secure code execution
20+
21+
subgraph UserSpace["<b>Your Worker</b>"]
22+
Worker["Application code using the methods exposed by the Sandbox SDK"]
23+
end
24+
25+
subgraph SDKSpace["<b>Sandbox SDK Implementation</b>"]
26+
DO["Sandbox Durable Object routes requests & maintains state"]
27+
Container["Isolated Ubuntu container executes untrusted code safely"]
28+
29+
DO -->|HTTP API| Container
30+
end
31+
32+
Worker -->|RPC call via the Durable Object stub returned by `getSandbox`| DO
33+
34+
style UserSpace fill:#fff8f0,stroke:#f6821f,stroke-width:2px
35+
style SDKSpace fill:#f5f5f5,stroke:#666,stroke-width:2px,stroke-dasharray: 5 5
36+
style Worker fill:#ffe8d1,stroke:#f6821f,stroke-width:2px
37+
style DO fill:#dce9f7,stroke:#1d8cf8,stroke-width:2px
38+
style Container fill:#d4f4e2,stroke:#17b26a,stroke-width:2px
4139
```
4240

4341
### Layer 1: Client SDK
@@ -70,7 +68,7 @@ export class Sandbox extends DurableObject<Env> {
7068
**Why Durable Objects**:
7169

7270
- **Persistent identity** - Same sandbox ID always routes to same instance
73-
- **State management** - Filesystem and processes persist between requests
71+
- **Container management** - Durable Object owns and manages the container lifecycle
7472
- **Geographic distribution** - Sandboxes run close to users
7573
- **Automatic scaling** - Cloudflare manages provisioning
7674

@@ -82,9 +80,8 @@ Executes code in isolation with full Linux capabilities.
8280

8381
**Why containers**:
8482

85-
- **True isolation** - Process-level isolation with namespaces
86-
- **Full environment** - Real Linux with Python, Node.js, Git, etc.
87-
- **Resource limits** - CPU, memory, disk constraints
83+
- **VM-based isolation** - Each sandbox runs in its own VM
84+
- **Full environment** - Ubuntu Linux with Python, Node.js, Git, etc.
8885

8986
## Request flow
9087

@@ -99,32 +96,6 @@ await sandbox.exec("python script.py");
9996
3. **Container Runtime** validates inputs, executes command, captures output
10097
4. **Response flows back** through all layers with proper error transformation
10198

102-
## State persistence
103-
104-
Sandboxes maintain state across requests:
105-
106-
**Filesystem**:
107-
108-
```typescript
109-
// Request 1
110-
await sandbox.writeFile("/workspace/data.txt", "hello");
111-
112-
// Request 2 (minutes later)
113-
const file = await sandbox.readFile("/workspace/data.txt");
114-
// Returns 'hello' - file persisted
115-
```
116-
117-
**Processes**:
118-
119-
```typescript
120-
// Request 1
121-
await sandbox.startProcess("node server.js");
122-
123-
// Request 2 (minutes later)
124-
const processes = await sandbox.listProcesses();
125-
// Server still running
126-
```
127-
12899
## Related resources
129100

130101
- [Sandbox lifecycle](/sandbox/concepts/sandboxes/) - How sandboxes are created and managed

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

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,11 @@ sidebar:
55
order: 3
66
---
77

8-
Each sandbox runs in an isolated Linux container based on Ubuntu 22.04.
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/).
99

10-
## Pre-installed software
10+
## Runtime software installation
1111

12-
The base container comes pre-packaged with a full development environment:
13-
14-
**Languages and runtimes**:
15-
- Python 3.11 (with pip)
16-
- Node.js 20 LTS (with npm)
17-
- Bun (JavaScript/TypeScript runtime)
18-
19-
**Python packages**:
20-
- NumPy - Numerical computing
21-
- pandas - Data analysis
22-
- Matplotlib - Plotting and visualization
23-
- IPython - Interactive Python
24-
25-
**Development tools**:
26-
- Git - Version control
27-
- Build tools (gcc, make, pkg-config)
28-
- Text editors (vim, nano)
29-
- Process monitoring (htop, procps)
30-
31-
**Utilities**:
32-
- curl, wget - HTTP clients
33-
- jq - JSON processor
34-
- Network tools (ping, dig, netstat)
35-
- Compression (zip, unzip)
36-
37-
Install additional software at runtime or [customize the base image](/sandbox/configuration/dockerfile/):
12+
Install additional software at runtime using standard package managers:
3813

3914
```bash
4015
# Python packages
@@ -43,8 +18,8 @@ pip install scikit-learn tensorflow
4318
# Node.js packages
4419
npm install express
4520

46-
# System packages
47-
apt-get install redis-server
21+
# System packages (requires apt-get update first)
22+
apt-get update && apt-get install -y redis-server
4823
```
4924

5025
## Filesystem

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ sidebar:
77

88
These pages explain how the Sandbox SDK works, why it's designed the way it is, and the concepts you need to understand to use it effectively.
99

10-
## Available concepts
11-
1210
- [Architecture](/sandbox/concepts/architecture/) - How the SDK is structured and why
1311
- [Sandbox lifecycle](/sandbox/concepts/sandboxes/) - Understanding sandbox states and behavior
1412
- [Container runtime](/sandbox/concepts/containers/) - How code executes in isolated containers

0 commit comments

Comments
 (0)