examples

Sử dụng khi làm việc trong thư mục examples/, chạy một ví dụ với wrangler dev, thêm một ví dụ mới, hoặc trả lời các câu hỏi về chỉ thị EXPOSE và…

npx skills add https://github.com/cloudflare/sandbox-sdk --skill examples

Examples

The examples/ directory contains working sample apps that exercise the SDK end-to-end. They double as integration smoke tests and as reference material for users.

Running an Example

From inside an example directory (e.g. examples/minimal/):

npm run dev    # Start wrangler dev (builds Docker on first run)

The first run builds the container image, so it's slow. Subsequent runs reuse the image unless the SDK or Dockerfile changes. If you've changed the container runtime or SDK, run npm run docker:rebuild from the repo root before npm run dev.

Available Examples

ExampleDemonstrates
minimalSmallest possible Sandbox SDK setup
authenticationAuth-protected sandbox access
claude-codeRunning Claude Code inside a sandbox
code-interpreterCodeInterpreter API + Workers AI
codex / codex-app-serverOpenAI Codex integration patterns
collaborative-terminalMulti-user terminal sharing
openai-agentsOpenAI Agents SDK + Sandbox
opencodeOpenCode integration
time-machineSnapshot/restore patterns
typescript-validatorRunning tsc against user code
vite-sandboxVite dev server proxied through preview URLs
websocket-tunnelWebSocket transport / port exposure
alpineAlpine-based container variant

EXPOSE Directives

The Cloudflare containers primitive does not require EXPOSE directives — all ports are accessible in both local dev and production without them.

Including EXPOSE is still recommended in example Dockerfiles because it documents which ports the app uses (standard Docker convention). Don't add it expecting it to gate access; add it as documentation.

Adding a New Example

  1. Copy examples/minimal/ as a starting point.
  2. Update package.json name and any wrangler config (wrangler.jsonc) — class names, DO bindings, container image tag.
  3. Add a README.md with an # H1 title (the README scanner uses it) and a short description of what the example demonstrates.
  4. Make sure the example builds and npm run dev works from a clean checkout.
  5. If the example demonstrates a new SDK capability, link to it from packages/sandbox/README.md.

Local Development Tips

  • Examples link to @cloudflare/sandbox via the workspace, so SDK changes are picked up after a build (npm run build from repo root).
  • Container changes require npm run docker:rebuild to take effect.
  • If you hit stale-image issues, delete the container image (docker images | grep sandbox) and re-run npm run dev.

Thêm skills từ cloudflare

workerd-api-review
cloudflare
Tối ưu hóa hiệu suất, thiết kế & tương thích API, lỗ hổng bảo mật và tuân thủ đặc tả tiêu chuẩn cho việc xem xét mã workerd. Bao gồm nhận biết tcmalloc…
official
workerd-safety-review
cloudflare
Các mẫu phát hiện về an toàn bộ nhớ, an toàn luồng, đồng thời và quan trọng cho việc xem xét mã workerd. Bao gồm các rủi ro ranh giới V8/KJ, quản lý vòng đời,…
official
module-registry
cloudflare
Tải khi làm việc với module registry trong workerd — đọc, sửa đổi, gỡ lỗi hoặc xem xét việc phân giải, biên dịch, đánh giá hoặc đăng ký module…
official
reproduce
cloudflare
Tái tạo một vấn đề GitHub của cloudflare/agents bằng cách tạo khung một dự án Agents/Worker tối thiểu và triển khai nó lên một tài khoản Cloudflare tạm thời, sau đó báo cáo…
official
local-explorer
cloudflare
Cách thêm sản phẩm/tài nguyên vào local explorer hoặc local API. Sử dụng khi triển khai các local API mới hoặc các route UI trong…
official
commit-categories
cloudflare
Quy tắc phân loại commit cho changelog và tóm tắt "có gì mới". PHẢI được tải trước khi phân loại commit trong changelog hoặc lệnh whats-new. Cung cấp…
official
architecture
cloudflare
Sử dụng khi lần đầu điều hướng cơ sở mã, thêm một phương thức client mới, thêm một trình xử lý/dịch vụ container mới, hoặc hiểu cách một yêu cầu luân chuyển…
official
changesets
cloudflare
Sử dụng khi tạo changeset, chuẩn bị phát hành hoặc nâng phiên bản. Bao gồm các gói cần tham chiếu, cách viết mô tả changeset hướng đến người dùng,…
official