Cloudflare Sandbox

Configure Cloudflare Sandbox on top of Durable Objects.

Cloudflare Sandbox fits apps that already run on Cloudflare and want provider-managed isolation close to the rest of the stack. ViteHub handles the Durable Object integration and keeps the Cloudflare-specific settings in the top-level sandbox config.

Before you start

Install the Cloudflare SDK alongside @vitehub/sandbox.

Terminal
pnpm add https://pkg.pr.new/nuxt-hub/agent/@vitehub/sandbox@main @cloudflare/sandbox

You also need a Cloudflare deployment so ViteHub can provision the sandbox runtime.

Configure Cloudflare

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vitehub/sandbox/nuxt'],
})

Cloudflare hosting picks the sandbox provider automatically. Set binding only when you need to override the default Durable Object binding name.

Cloudflare-specific options

Set Cloudflare-specific options such as sandboxId, keepAlive, sleepAfter, and normalizeId in the top-level sandbox config. These are provider settings, not definition options.

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vitehub/sandbox/nuxt'],
  sandbox: {
    sandboxId: 'release-notes',
    keepAlive: true,
    sleepAfter: '10m',
  },
})

Define a sandbox

Sandbox definitions accept only portable options (timeout, env, runtime).

server/sandboxes/release-notes.ts
import { defineSandbox } from '@vitehub/sandbox'

export default defineSandbox(async (payload?: { notes?: string }) => {
  return { notes: payload?.notes || '' }
}, {
  timeout: 30_000,
})

What changes on Cloudflare

ConcernBehavior
Sandbox identityUse sandboxId when repeated calls should reuse the same Cloudflare sandbox identity.
Binding resolutionViteHub resolves the Durable Object binding from sandbox.binding or falls back to the default Cloudflare binding.
Provider optionsUse keepAlive, sleepAfter, and normalizeId in the top-level sandbox config.
Choose Cloudflare when the rest of the app already relies on Workers and Durable Objects. Leave sandboxId undefined when every execution should stay ephemeral.