Skip to content

Commit aa106ee

Browse files
committed
Fix the architecture diagram
1 parent 08b6c59 commit aa106ee

File tree

1 file changed

+31
-60
lines changed

1 file changed

+31
-60
lines changed

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+
- **State management** - Durable Object persists state across ephemeral container restarts
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

0 commit comments

Comments
 (0)