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
This guide will walk you through creating your first secure code execution environment using Sandbox SDK. You'll learn how to:
10
+
Build your first application with Sandbox SDK - a secure code execution environment running on Cloudflare's global network. In this guide, you'll create a Worker that can execute Python code and work with files in isolated containers.
11
11
12
-
- Create a Worker that can execute code in isolated sandboxes
13
-
- Run commands and capture output
14
-
- Work with files in the sandbox
15
-
- Deploy your application globally
16
-
17
-
By the end of this guide, you'll have a working sandbox that can safely execute Python code.
12
+
:::note[What you're building]
13
+
A simple API that can safely execute Python code and perform file operations, all running in isolated sandbox environments on Cloudflare's edge network.
14
+
:::
18
15
19
16
## Prerequisites
20
17
21
18
<Renderfile="prereqs"product="workers" />
22
19
23
20
### Ensure Docker is running locally
24
21
25
-
Sandbox SDK uses [Docker](https://www.docker.com/) to build and push container images alongside your Worker. Docker must be running locally when you run `wrangler deploy`. The easiest way to install Docker is to follow the [Docker Desktop installation guide](https://docs.docker.com/desktop/).
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.
23
+
24
+
Install Docker by following the [Docker Desktop installation guide](https://docs.docker.com/desktop/).
26
25
27
-
You can verify Docker is running by executing:
26
+
Verify Docker is running:
28
27
29
28
```sh
30
29
docker info
31
30
```
32
31
33
-
If Docker is running, the command will succeed. If not, it will hang or return "Cannot connect to the Docker daemon".
32
+
If Docker is not running, this command will hang or return "Cannot connect to the Docker daemon".
34
33
35
-
## 1. Create your first sandbox project
34
+
## 1. Create a new project
36
35
37
-
Create a new project using the Sandbox SDK template:
The first time you run `wrangler dev`, it will build the Docker container image. This may take a few minutes. Subsequent runs will be much faster due to Docker's layer caching.
117
+
First run builds the Docker container (2-3 minutes). Subsequent runs are much faster due to caching.
164
118
:::
165
119
166
-
Once the dev server is running, open your browser and visit:
-`http://localhost:8787/file` - Test file operations
122
+
```sh
123
+
# Execute Python code
124
+
curl http://localhost:8787/run
170
125
171
-
You should see JSON responses with the output from each operation.
126
+
# File operations
127
+
curl http://localhost:8787/file
128
+
```
172
129
173
-
## 5. Deploy your sandbox
130
+
You should see JSON responses with the command output and file contents.
174
131
175
-
Deploy your Worker and sandbox container to Cloudflare's global network:
132
+
## 4. Deploy to production
133
+
134
+
Deploy your Worker and container:
176
135
177
136
```sh
178
137
npx wrangler deploy
179
138
```
180
139
181
-
When you run `wrangler deploy`:
182
-
183
-
1. Wrangler builds your container image using Docker
184
-
2. The image is pushed to Cloudflare's Container Registry
185
-
3. Your Worker is deployed with the sandbox configuration
140
+
This will:
141
+
1. Build your container image using Docker
142
+
2. Push it to Cloudflare's Container Registry
143
+
3. Deploy your Worker globally
186
144
187
-
:::note
188
-
After your first deployment, wait 2-3 minutes for the container to be fully provisioned before making requests. During this time, the Worker is deployed but sandbox operations may error.
145
+
:::caution[Wait for provisioning]
146
+
After first deployment, wait 2-3 minutes before making requests. The Worker deploys immediately, but the container needs time to provision.
189
147
:::
190
148
191
-
### Check deployment status
192
-
193
-
Verify your sandbox is ready:
149
+
Check deployment status:
194
150
195
151
```sh
196
152
npx wrangler containers list
197
153
```
198
154
199
-
This shows all containers in your account and their deployment status.
200
-
201
-
## 6. Test your deployed sandbox
155
+
## 5. Test your deployment
202
156
203
-
Visit your deployed Worker URL (shown in the deploy output):
For detailed configuration options including environment variables, secrets, and custom images, see the [Wrangler configuration reference](/sandbox/configuration/wrangler/).
219
204
220
205
## Next steps
221
206
222
-
- Learn about [command execution](/sandbox/guides/execute-commands/) with streaming output
223
-
- Explore [file operations](/sandbox/guides/manage-files/) and working with projects
224
-
- Set up [preview URLs](/sandbox/guides/expose-services/) to expose services running in your sandbox
225
-
- Review the [API reference](/sandbox/api/) for all available methods
226
-
- Check out [examples](/sandbox/examples/) including AI code execution and data analysis
207
+
Now that you have a working sandbox, explore more capabilities:
208
+
209
+
-[Execute commands](/sandbox/guides/execute-commands/) - Run shell commands and stream output
210
+
-[Manage files](/sandbox/guides/manage-files/) - Work with files and directories
211
+
-[Expose services](/sandbox/guides/expose-services/) - Get public URLs for services running in your sandbox
212
+
-[API reference](/sandbox/api/) - Complete API documentation
0 commit comments