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.4---56# Cloudflare Sandbox SDK78Use current Cloudflare docs and the installed package as the API contract. The9SDK and its container topology evolve quickly; inspect package exports, types,10Wrangler schema, and generated configuration before coding.1112## Establish the isolation contract1314Identify:1516- who chooses the sandbox ID and how it is scoped to a tenant or session;17- which code, files, environment variables, and network access are untrusted;18- what must survive container sleep or recreation;19- which operations need a shared session versus isolated execution; and20- whether an exposed service is private, temporary, or public.2122A Sandbox is backed by a Durable Object and its container starts lazily. The23same ID selects the same logical Sandbox, but container-local files, processes,24and shell state can be lost after sleep or restart. Put durable application state25outside the ephemeral container filesystem.2627## Configure from current docs2829Verify the exact container, Durable Object binding, and class lifecycle required30by the installed SDK. Re-export the SDK's `Sandbox` class from the Worker when31the current integration requires it. Do not copy a pinned image tag, lifecycle32declaration, instance type, or preview-domain configuration from this skill.3334Use [api-quick-ref.md](references/api-quick-ref.md) only after checking installed35types. Use [examples.md](references/examples.md) to locate a relevant upstream36example rather than combining several patterns speculatively.3738## Choose execution deliberately3940- Use command/process APIs when exit status, streams, or process lifecycle is the41 contract.42- Use code-interpreter APIs when structured rich results or a deliberate session43 is required.44- Disable or avoid shared default sessions when calls must be isolated.45- Scope IDs and credentials so one tenant cannot address another tenant's46 sandbox.47- Bound input, runtime, output, files, processes, and cleanup according to the48 untrusted-code threat model.49- Treat preview URLs as public capabilities unless an owning authentication layer50 proves otherwise. Check current custom-domain and tunnel requirements.5152## Verify the real lifecycle5354Test the exact package version and generated Worker bundle. Exercise creation,55one representative command or code run, expected file/session behavior,56sleep/recreation when persistence matters, cleanup, and any exposed route.57Successful object creation alone does not prove container execution or preview58routing.