Skip to content

Commit 93f36b6

Browse files
committed
Improve sandbox getting started links
1 parent e536cb3 commit 93f36b6

File tree

4 files changed

+118
-97
lines changed

4 files changed

+118
-97
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/get-started.mdx

Lines changed: 63 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,9 @@ A simple API that can safely execute Python code and perform file operations in
1919

2020
### Ensure Docker is running locally
2121

22-
Sandbox SDK uses [Docker](https://www.docker.com/) to build container images alongside your Worker. Docker must be running when you deploy or run locally.
22+
Sandbox SDK uses [Docker](https://www.docker.com/) to build container images alongside your Worker.
2323

24-
Install Docker by following the [Docker Desktop installation guide](https://docs.docker.com/desktop/).
25-
26-
Verify Docker is running:
27-
28-
```sh
29-
docker info
30-
```
31-
32-
If Docker is not running, this command will hang or return "Cannot connect to the Docker daemon".
24+
<Render product="containers" file="docker-setup" />
3325

3426
## 1. Create a new project
3527

@@ -56,61 +48,58 @@ cd my-sandbox
5648
The template provides a minimal Worker that demonstrates core sandbox capabilities:
5749

5850
```typescript
59-
import { getSandbox, proxyToSandbox, type Sandbox } from '@cloudflare/sandbox';
51+
import { getSandbox, proxyToSandbox, type Sandbox } from "@cloudflare/sandbox";
6052

61-
export { Sandbox } from '@cloudflare/sandbox';
53+
export { Sandbox } from "@cloudflare/sandbox";
6254

6355
type Env = {
64-
Sandbox: DurableObjectNamespace<Sandbox>;
56+
Sandbox: DurableObjectNamespace<Sandbox>;
6557
};
6658

6759
export default {
68-
async fetch(request: Request, env: Env): Promise<Response> {
69-
// Required for preview URLs (if you expose ports later)
70-
const proxyResponse = await proxyToSandbox(request, env);
71-
if (proxyResponse) return proxyResponse;
72-
73-
const url = new URL(request.url);
74-
75-
// Get or create a sandbox instance
76-
const sandbox = getSandbox(env.Sandbox, 'my-sandbox');
77-
78-
// Execute Python code
79-
if (url.pathname === '/run') {
80-
const result = await sandbox.exec('python -c "print(2 + 2)"');
81-
return Response.json({
82-
output: result.stdout,
83-
success: result.success
84-
});
85-
}
86-
87-
// Work with files
88-
if (url.pathname === '/file') {
89-
await sandbox.writeFile('/workspace/hello.txt', 'Hello, Sandbox!');
90-
const file = await sandbox.readFile('/workspace/hello.txt');
91-
return Response.json({
92-
content: file.content
93-
});
94-
}
95-
96-
return new Response('Try /run or /file');
97-
},
60+
async fetch(request: Request, env: Env): Promise<Response> {
61+
const url = new URL(request.url);
62+
63+
// Get or create a sandbox instance
64+
const sandbox = getSandbox(env.Sandbox, "my-sandbox");
65+
66+
// Execute Python code
67+
if (url.pathname === "/run") {
68+
const result = await sandbox.exec('python3 -c "print(2 + 2)"');
69+
return Response.json({
70+
output: result.stdout,
71+
error: result.stderr,
72+
exitCode: result.exitCode,
73+
success: result.success,
74+
});
75+
}
76+
77+
// Work with files
78+
if (url.pathname === "/file") {
79+
await sandbox.writeFile("/workspace/hello.txt", "Hello, Sandbox!");
80+
const file = await sandbox.readFile("/workspace/hello.txt");
81+
return Response.json({
82+
content: file.content,
83+
});
84+
}
85+
86+
return new Response("Try /run or /file");
87+
},
9888
};
9989
```
10090

10191
**Key concepts**:
10292

103-
- `getSandbox()` - Gets or creates a sandbox instance by ID
104-
- `proxyToSandbox()` - Required at the top for preview URLs to work
105-
- `sandbox.exec()` - Execute commands and capture output
106-
- `sandbox.writeFile()` / `readFile()` - File operations
93+
- `getSandbox()` - Gets or creates a sandbox instance by ID. Use the same ID to reuse the same sandbox instance across requests.
94+
- `sandbox.exec()` - Execute shell commands in the sandbox and capture stdout, stderr, and exit codes.
95+
- `sandbox.writeFile()` / `readFile()` - Write and read files in the sandbox filesystem.
10796

10897
## 3. Test locally
10998

11099
Start the development server:
111100

112101
```sh
113-
npm run dev
102+
npm run dev. If you expect to have multiple sandbox instances, you can increase `max_instances`.
114103
```
115104

116105
:::note
@@ -138,6 +127,7 @@ npx wrangler deploy
138127
```
139128

140129
This will:
130+
141131
1. Build your container image using Docker
142132
2. Push it to Cloudflare's Container Registry
143133
3. Deploy your Worker globally
@@ -171,34 +161,36 @@ Your `wrangler.jsonc` connects three pieces together:
171161

172162
```jsonc
173163
{
174-
"containers": [
175-
{
176-
"class_name": "Sandbox",
177-
"image": "./Dockerfile"
178-
}
179-
],
180-
"durable_objects": {
181-
"bindings": [
182-
{
183-
"class_name": "Sandbox",
184-
"name": "Sandbox"
185-
}
186-
]
187-
},
188-
"migrations": [
189-
{
190-
"new_sqlite_classes": ["Sandbox"],
191-
"tag": "v1"
192-
}
193-
]
164+
"containers": [
165+
{
166+
"class_name": "Sandbox",
167+
"image": "./Dockerfile",
168+
"instance_type": "lite",
169+
"max_instances": 1,
170+
},
171+
],
172+
"durable_objects": {
173+
"bindings": [
174+
{
175+
"class_name": "Sandbox",
176+
"name": "Sandbox",
177+
},
178+
],
179+
},
180+
"migrations": [
181+
{
182+
"new_sqlite_classes": ["Sandbox"],
183+
"tag": "v1",
184+
},
185+
],
194186
}
195187
```
196188

197189
</WranglerConfig>
198190

199-
- **containers** - Your Dockerfile defines the execution environment
200-
- **durable_objects** - Makes the `Sandbox` binding available in your Worker
201-
- **migrations** - Initializes Durable Object storage (required once)
191+
- **containers** - Defines the [container image, instance type, and resource limits](/workers/wrangler/configuration/#containers) for your sandbox environment. If you expect to have multiple sandbox instances, you can increase `max_instances`.
192+
- **durable_objects** - You need not be familiar with [Durable Objects](/durable-objects) to use Sandbox SDK, but if you'd like, you can [learn more about Cloudflare Containers and Durable Objects](/containers/get-started/#each-container-is-backed-by-its-own-durable-object). This configuration creates a [binding](/workers/runtime-apis/bindings#what-is-a-binding) that makes the `Sandbox` Durable Object accessible in your Worker code.
193+
- **migrations** - Registers the `Sandbox` class, implemented by the Sandbox SDK, with [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage) (required once)
202194

203195
For detailed configuration options including environment variables, secrets, and custom images, see the [Wrangler configuration reference](/sandbox/configuration/wrangler/).
204196

src/content/docs/sandbox/index.mdx

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ df['sales'].sum() # Last expression is automatically returned
128128

129129
<Feature header="Execute commands securely" href="/sandbox/guides/execute-commands/" cta="Learn about command execution">
130130

131-
Run shell commands, Python scripts, Node.js applications, and more in isolated containers with streaming output support and automatic timeout handling.
131+
Run shell commands, Python scripts, Node.js applications, and more with streaming output support and automatic timeout handling.
132132

133133
</Feature>
134134

@@ -144,6 +144,12 @@ Expose HTTP services running in your sandbox with automatically generated previe
144144

145145
</Feature>
146146

147+
<Feature header="Execute code directly" href="/sandbox/guides/code-execution/" cta="Learn about code execution">
148+
149+
Execute Python and JavaScript code with rich outputs including charts, tables, and images. Maintain persistent state between executions for AI-generated code and interactive workflows.
150+
151+
</Feature>
152+
147153
---
148154

149155
## Use Cases
@@ -156,7 +162,7 @@ Execute code generated by Large Language Models safely and reliably. Perfect for
156162

157163
### Data Analysis & Notebooks
158164

159-
Create interactive data analysis environments with Python, pandas, and visualization libraries. Build notebook-like experiences at the edge.
165+
Create interactive data analysis environments with pandas, NumPy, and Matplotlib. Generate charts, tables, and visualizations with automatic rich output formatting.
160166

161167
### Interactive Development Environments
162168

@@ -194,35 +200,34 @@ Stateful coordination layer that enables Sandbox to maintain persistent environm
194200

195201
<CardGrid>
196202

197-
<LinkTitleCard title="Tutorials" href="/sandbox/tutorials/" icon="pen">
203+
<LinkTitleCard title="Tutorials" href="/sandbox/tutorials/" icon="open-book">
198204
Explore complete examples including AI code execution, data analysis, and
199205
interactive environments.
200206
</LinkTitleCard>
201207

202208
<LinkTitleCard
203-
title="Beta Information"
204-
href="/sandbox/platform/beta-info/"
205-
icon="seti:shell"
209+
title="How-to Guides"
210+
href="/sandbox/guides/"
211+
icon="seti:notebook"
206212
>
207-
Learn about the Sandbox Beta, current status, and upcoming features.
213+
Learn how to solve specific problems and implement features with the Sandbox
214+
SDK.
208215
</LinkTitleCard>
209216

210-
<LinkTitleCard
211-
title="Pricing"
212-
href="/sandbox/platform/pricing/"
213-
icon="document"
214-
>
215-
Understand Sandbox pricing based on the underlying Containers platform.
217+
<LinkTitleCard title="API Reference" href="/sandbox/api/" icon="seti:json">
218+
Explore the complete API documentation for the Sandbox SDK.
216219
</LinkTitleCard>
217220

218-
<LinkTitleCard title="Limits" href="/sandbox/platform/limits/" icon="document">
219-
Learn about resource limits, quotas, and best practices for working within
220-
them.
221+
<LinkTitleCard title="Concepts" href="/sandbox/concepts/" icon="seti:info">
222+
Learn about the key concepts and architecture of the Sandbox SDK.
221223
</LinkTitleCard>
222224

223-
<LinkTitleCard title="How-to Guides" href="/sandbox/guides/" icon="seti:lock">
224-
Learn how to solve specific problems and implement features with the Sandbox
225-
SDK.
225+
<LinkTitleCard
226+
title="Configuration"
227+
href="/sandbox/configuration/"
228+
icon="setting"
229+
>
230+
Learn about the configuration options for the Sandbox SDK.
226231
</LinkTitleCard>
227232

228233
<LinkTitleCard
@@ -234,12 +239,33 @@ Stateful coordination layer that enables Sandbox to maintain persistent environm
234239
</LinkTitleCard>
235240

236241
<LinkTitleCard
237-
title="Developer Discord"
242+
title="Beta Information"
243+
href="/sandbox/platform/beta-info/"
244+
icon="warning"
245+
>
246+
Learn about the Sandbox Beta, current status, and upcoming features.
247+
</LinkTitleCard>
248+
249+
<LinkTitleCard
250+
title="Pricing"
251+
href="/sandbox/platform/pricing/"
252+
icon="seti:shell"
253+
>
254+
Understand Sandbox pricing based on the underlying Containers platform.
255+
</LinkTitleCard>
256+
257+
<LinkTitleCard title="Limits" href="/sandbox/platform/limits/" icon="error">
258+
Learn about resource limits, quotas, and best practices for working within
259+
them.
260+
</LinkTitleCard>
261+
262+
<LinkTitleCard
263+
title="Discord Community"
238264
href="https://discord.cloudflare.com"
239265
icon="discord"
240266
>
241-
Connect with the Workers community on Discord. Ask questions, share what
242-
you're building, and get help from other developers.
267+
Connect with the community on Discord. Ask questions, share what you're
268+
building, and get help from other developers.
243269
</LinkTitleCard>
244270

245271
</CardGrid>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
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.
2+
3+
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,
4+
the `docker info` command will hang or return an error including the message "Cannot connect to the Docker daemon".

0 commit comments

Comments
 (0)