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

dependabot-review
cloudflare
Phân tích một PR Dependabot để xác định những gì thực sự thay đổi trong từng gói được nâng cấp và liệu những thay đổi đó có ảnh hưởng đến repo này hay không. Báo cáo các API/phương thức đã thay đổi,…
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…
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…
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…
open-pr
cloudflare
Lấy một issue GitHub từ cloudflare/agents cùng với các phát hiện tái hiện lỗi và tạo một PR sửa lỗi một lần — tạo nhánh, thay đổi, kiểm thử, đẩy lên, và mở PR liên kết với issue đó.
write-endpoints
cloudflare
Hướng dẫn toàn diện để xây dựng các điểm cuối OpenAPI với chanfana - định nghĩa schema, xác thực yêu cầu, các thao tác CRUD, tích hợp cơ sở dữ liệu D1, và…
agents-sdk
cloudflare
Xây dựng AI agent trên Cloudflare Workers bằng Agents SDK. Tải khi tạo agent có trạng thái, quy trình làm việc bền vững, ứng dụng WebSocket thời gian thực, tác vụ theo lịch trình,…
changelog
cloudflare
Tạo, cập nhật và xem xét các mục nhật ký thay đổi sản phẩm cho trang tài liệu Cloudflare. Tải khi tạo tệp MDX nhật ký thay đổi, chỉnh sửa các tệp hiện có…