
Architecture
- 22 installs
- 1.1k repo stars
- Updated August 4, 2026
- cloudflare/sandbox-sdk
architecture explains Cloudflare Sandbox SDK layers and request flow.
About
The architecture skill for Cloudflare Sandbox SDK explains the three-layer system: @cloudflare/sandbox public npm SDK with Sandbox Durable Object and modular clients, @repo/shared internal types and errors, and @repo/sandbox-container Bun runtime inside Docker. Request flow covers the primary control path from Worker through Sandbox DO, ContainerControlClient, capnweb RPC WebSocket to SandboxControlAPI, and shell or filesystem services, plus a route-based HTTP compatibility path on port 3000. Errors propagate back using shared ErrorCode enum classes. Guidance helps when navigating the codebase first time, adding client methods, container handlers, or tracing requests end to end. Monorepo layout maps packages, publish boundaries, and which artifacts ship to npm versus Docker images. The primary Sandbox Durable Object to container control path is the container-control/control-plane path: Control-channel/transport-layer capabilities belong in this path. Treat capnweb/RPC as the current implementation detail, not the architectural boundary.
- Explains Sandbox SDK three-layer package architecture.
- Documents Worker to container primary RPC control path.
- Covers HTTP compatibility route on port 3000.
- Maps error propagation via shared ErrorCode classes.
- Guides adding clients, handlers, and tracing requests.
Architecture by the numbers
- 22 all-time installs (skills.sh)
- Ranked #808 of 1,039 Cloud & Infrastructure skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
architecture capabilities & compatibility
- Capabilities
- three layer architecture section · request flow primary and compatibility paths
- Works with
- cloudflare · docker
- Use cases
- api development · devops
- Platforms
- macOS · Linux
What architecture says it does
Public SDK published to npm
npx skills add https://github.com/cloudflare/sandbox-sdk --skill architectureAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 22 |
|---|---|
| repo stars | ★ 1.1k |
| Last updated | August 4, 2026 |
| Repository | cloudflare/sandbox-sdk ↗ |
How does a Sandbox SDK request reach the container runtime?
Navigate Cloudflare Sandbox SDK three-layer architecture and request flow paths.
Who is it for?
Developers extending Cloudflare Sandbox SDK or container runtime.
Skip if: Skip for unrelated Cloudflare Workers without Sandbox SDK.
When should I use this skill?
User navigates sandbox-sdk codebase or adds client methods.
What you get
Clear map of SDK packages, RPC path, and error flow.
Files
Architecture
Three-Layer Architecture
1. `@cloudflare/sandbox` (`packages/sandbox/`) — Public SDK published to npm
Sandboxclass: Durable Object that manages the container lifecycle- Modular HTTP clients per capability (
CommandClient,FileClient,ProcessClient, …) CodeInterpreter: high-level API for Python/JS with structured outputsproxyToSandbox(): request handler for preview URL routing
2. `@repo/shared` (`packages/shared/`) — Internal shared utilities
- Type definitions used by both SDK and container runtime
- Centralized error classes (
packages/shared/src/errors/) and logging - Not published to npm
3. `@repo/sandbox-container` (`packages/sandbox-container/`) — Container runtime
- Bun-based HTTP server running inside the Docker container
- Dependency-injection container in
core/container.ts - Route handlers for command execution, file operations, process management
- Not published to npm (bundled into the Docker image)
Request Flow
Primary control path:
Worker
→ Sandbox DO (packages/sandbox)
→ ContainerControlClient (packages/sandbox/src/container-control/)
→ capnweb over /rpc WebSocket
→ SandboxControlAPI (packages/sandbox-container/src/control-plane/)
→ container services
→ Shell commands / filesystemRoute-based compatibility path:
Worker
→ Sandbox DO (packages/sandbox)
→ SandboxClient / clients/transport
→ Container HTTP API on port 3000 (packages/sandbox-container)
→ Router / handlers
→ container services
→ Shell commands / filesystemErrors flow back the same path: container → Sandbox DO → Worker, using the custom error classes in packages/shared/src/errors/ keyed by the ErrorCode enum.
Primary Control Path
The primary Sandbox Durable Object to container control path is the container-control/control-plane path:
- SDK side:
packages/sandbox/src/container-control/ - Container side:
packages/sandbox-container/src/control-plane/ - Current wire implementation: capnweb RPC over the
/rpcWebSocket route
Control-channel/transport-layer capabilities belong in this path. Treat capnweb/RPC as the current implementation detail, not the architectural boundary.
The shared @repo/shared SandboxAPI interface remains named SandboxAPI because it defines the current control API contract used by both sides.
Route-Based Compatibility Path (packages/sandbox/src/clients/)
packages/sandbox/src/clients/ and packages/sandbox/src/clients/transport/ implement the HTTP and custom WebSocket route-based compatibility API. Maintain these for compatibility, debugging, local development, fallback behavior, and bug fixes, but do not add new control-plane capabilities there by default.
The route-based client pattern is:
- `BaseHttpClient` — abstract route-based HTTP/WebSocket client with shared request/response handling
- `SandboxClient` — compatibility aggregator that exposes all specialized route-based clients
- Specialized clients — one per domain:
CommandClient— exec / execStreamFileClient— read, write, list, deleteProcessClient— start, stop, list, signalPortClient— port readiness streamsGitClient— clone, checkout, statusUtilityClient— ping, metadataInterpreterClient— code interpreter sessions
When maintaining route-based compatibility, add or extend specialized clients under packages/sandbox/src/clients/. DO-to-container control capabilities belong in packages/sandbox/src/container-control/ and packages/sandbox-container/src/control-plane/.
Container Runtime (packages/sandbox-container/src/)
- DI container (
core/container.ts) — manages service lifecycle and wiring - Router — simple HTTP router with middleware
- Control plane (
control-plane/) — primary container-side API called by the Sandbox DO - Handlers (
handlers/) — route-based compatibility handlers, thin layer that parses requests - Services (
services/) — business logic (CommandService,FileService,ProcessService, …) - Managers (
managers/) — stateful coordinators such asProcessManager
Entry point: packages/sandbox-container/src/index.ts starts a Bun HTTP server on port 3000.
When adding a new container control operation:
1. Add/extend a service in services/ for the business logic. 2. Add the control-plane method in packages/sandbox-container/src/control-plane/. 3. Mirror the call in packages/sandbox/src/container-control/. 4. Add unit tests on both sides; add an E2E test if it touches real shell/filesystem behavior.
Only add a route handler in handlers/ and a route-based SDK client in packages/sandbox/src/clients/ when maintaining HTTP/WebSocket compatibility.
Monorepo Structure
Uses npm workspaces + Turbo:
packages/sandbox— main SDK package (published)packages/shared— shared types and utilities (internal)packages/sandbox-container— container runtime (internal, bundled into image)examples/— working example projectstooling/— shared TypeScript configs
turbo.json orchestrates dependency-aware builds.
Cross-Cutting Patterns
- Sessions — isolate execution contexts (cwd, env vars). Default session is auto-created; multiple sessions per sandbox are supported.
- Ports — expose internal services via preview URLs with token auth. Preview URL authorization is Durable Object-owned, while forwarding is active only after
exposePort()activates the port for the current runtime. Production preview URLs require a custom domain with wildcard DNS (*.yourdomain.com);.workers.devdoes not support the required subdomain patterns. - Container isolation — handled at the Cloudflare platform level (VMs), not by SDK code.
Container Base Image
The container runtime uses Ubuntu 22.04 with:
- Python 3.11 (matplotlib, numpy, pandas, ipython)
- Node.js 20 LTS
- Bun 1.x (powers the container HTTP server)
- Git, curl, wget, jq, and other common utilities
When modifying packages/sandbox/Dockerfile:
- Keep images lean — every MB affects cold start
- Pin versions for reproducibility
- Clean up package manager caches to reduce image size
Related skills
FAQ
What does architecture do?
architecture explains Cloudflare Sandbox SDK layers and request flow.
When should I use architecture?
User navigates sandbox-sdk codebase or adds client methods.
Is this skill safe to install?
Review the Security Audits panel on this page before installing in production.