Cloudflare
Cloudflare provider for ComputeSDK - Execute code in secure, isolated sandboxes on Cloudflare's edge network.
Installation
Setup
Remote mode uses the bridge Worker shipped in packages/cloudflare/worker. It requires a Workers Paid account and Docker to build the container images. See the Worker source for deployment configuration.
You can print these setup instructions at any time by running:
Note: This command only prints instructions — it does not deploy anything and does not require Docker.
Step 1: Deploy the bridge Worker
From a checkout, enter packages/cloudflare/worker, run npm ci, authenticate with npx wrangler login, set the secret below, then run npx wrangler deploy.
Step 2: Set the Worker's API key secret
From the bridge Worker project, set a strong generated SANDBOX_API_KEY secret:
Step 3: Configure your app
Add the Worker URL and the same API key to your .env file:
These are the only env vars needed at runtime.
Snapshots and preview URLs
The adapter checks the Worker's GET /v1/info feature list. The bridge supports native files, HTTP/WebSocket preview URLs, and filesystem snapshots; an older demo Worker remains usable for commands/files but does not gain these features automatically.
snapshot.create(instanceId) captures the writable rootfs while keeping the container running. Restore with instances.create({ snapshotId }). Snapshots preserve files, not memory or processes. Data expires 30 days after creation or last restore; snapshot.delete removes the bridge's handle, not the underlying retained data. The adapter does not yet declare snapshot.capabilities, so do not infer unified memory/fork flags from method availability.
sandbox.getUrl({ port }) works with the bridge. The server must listen on 0.0.0.0; preview URLs forward HTTP and WebSockets and are accessible to anyone with the URL, without an API key.
Usage
Run Commands
Filesystem
Environment Variables
Pass environment variables at the provider level:
Or per-sandbox at creation time:
Sandbox Size and Image
Choose the size and image of a new sandbox when you create it:
vcpu
vCPUs of a custom instance type
memoryMib
Memory of the custom instance type, in MiB
diskMb
Disk of the custom instance type, in MB
image
Name of an image declared by the sandbox demo Worker. builder has Node.js 24 and common build tools.
Set vcpu, memoryMib, and diskMb together. Without them, the sandbox uses the Worker's default instance type. Without image, it uses the Worker's default image.
Configuration Options
Direct Mode
A Cloudflare Worker can call the sandbox demo Worker's Durable Object directly instead of using its HTTP API. Add a cross-script Durable Object binding to the Worker that uses ComputeSDK:
Pass the binding to the provider:
Limitations
Resource limits apply based on your Cloudflare plan
Some system calls may be restricted in the container environment
Preview URLs require the bridge Worker's advertised port support; older demo Workers do not support them
Listing all sandboxes is not supported — use
getByIdto reconnect to a specific sandbox
Last updated
Was this helpful?