Cloudflare Sandbox SDK
Use current Cloudflare docs and the installed package as the API contract. The
SDK and its container topology evolve quickly; inspect package exports, types,
Wrangler schema, and generated configuration before coding.
Establish the isolation contract
Identify:
- who chooses the sandbox ID and how it is scoped to a tenant or session;
- which code, files, environment variables, and network access are untrusted;
- what must survive container sleep or recreation;
- which operations need a shared session versus isolated execution; and
- whether an exposed service is private, temporary, or public.
A Sandbox is backed by a Durable Object and its container starts lazily. The
same ID selects the same logical Sandbox, but container-local files, processes,
and shell state can be lost after sleep or restart. Put durable application state
outside the ephemeral container filesystem.
Configure from current docs
Verify the exact container, Durable Object binding, and class lifecycle required
by the installed SDK. Re-export the SDK's Sandbox class from the Worker when
the current integration requires it. Do not copy a pinned image tag, lifecycle
declaration, instance type, or preview-domain configuration from this skill.
Use api-quick-ref.md only after checking installed
types. Use examples.md to locate a relevant upstream
example rather than combining several patterns speculatively.
Choose execution deliberately
- Use command/process APIs when exit status, streams, or process lifecycle is the
contract.
- Use code-interpreter APIs when structured rich results or a deliberate session
is required.
- Disable or avoid shared default sessions when calls must be isolated.
- Scope IDs and credentials so one tenant cannot address another tenant's
sandbox.
- Bound input, runtime, output, files, processes, and cleanup according to the
untrusted-code threat model.
- Treat preview URLs as public capabilities unless an owning authentication layer
proves otherwise. Check current custom-domain and tunnel requirements.
Verify the real lifecycle
Test the exact package version and generated Worker bundle. Exercise creation,
one representative command or code run, expected file/session behavior,
sleep/recreation when persistence matters, cleanup, and any exposed route.
Successful object creation alone does not prove container execution or preview
routing.
1---2name: sandbox-sdk3description: Build or debug applications that specifically use Cloudflare Sandbox SDK (`@cloudflare/sandbox`) for isolated command execution, code interpretation, files, processes, sessions, or preview URLs. Do not trigger for generic container design, local shell scripting, or unrelated sandbox products.4metadata:5 source: https://skillmd.com/skills/swyxio/sandbox-sdk6---78# Cloudflare Sandbox SDK910Use current Cloudflare docs and the installed package as the API contract. The11SDK and its container topology evolve quickly; inspect package exports, types,12Wrangler schema, and generated configuration before coding.1314## Establish the isolation contract1516Identify:1718- who chooses the sandbox ID and how it is scoped to a tenant or session;19- which code, files, environment variables, and network access are untrusted;20- what must survive container sleep or recreation;21- which operations need a shared session versus isolated execution; and22- whether an exposed service is private, temporary, or public.2324A Sandbox is backed by a Durable Object and its container starts lazily. The25same ID selects the same logical Sandbox, but container-local files, processes,26and shell state can be lost after sleep or restart. Put durable application state27outside the ephemeral container filesystem.2829## Configure from current docs3031Verify the exact container, Durable Object binding, and class lifecycle required32by the installed SDK. Re-export the SDK's `Sandbox` class from the Worker when33the current integration requires it. Do not copy a pinned image tag, lifecycle34declaration, instance type, or preview-domain configuration from this skill.3536Use [api-quick-ref.md](references/api-quick-ref.md) only after checking installed37types. Use [examples.md](references/examples.md) to locate a relevant upstream38example rather than combining several patterns speculatively.3940## Choose execution deliberately4142- Use command/process APIs when exit status, streams, or process lifecycle is the43 contract.44- Use code-interpreter APIs when structured rich results or a deliberate session45 is required.46- Disable or avoid shared default sessions when calls must be isolated.47- Scope IDs and credentials so one tenant cannot address another tenant's48 sandbox.49- Bound input, runtime, output, files, processes, and cleanup according to the50 untrusted-code threat model.51- Treat preview URLs as public capabilities unless an owning authentication layer52 proves otherwise. Check current custom-domain and tunnel requirements.5354## Verify the real lifecycle5556Test the exact package version and generated Worker bundle. Exercise creation,57one representative command or code run, expected file/session behavior,58sleep/recreation when persistence matters, cleanup, and any exposed route.59Successful object creation alone does not prove container execution or preview60routing.