Unified sandbox API for isolated code execution on Vercel and Cloudflare.
pnpm installnuxt.config.ts enables zero-config sandboxing:
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@nuxt/ui'],
hub: { sandbox: true },
compatibilityDate: '2024-09-19',
})hubSandbox(options) > NUXT_HUB_SANDBOX_* > hub.sandbox > auto-detect
| Env Var | Description |
|---|---|
NUXT_HUB_SANDBOX_PROVIDER |
vercel or cloudflare |
NUXT_HUB_SANDBOX_RUNTIME |
Vercel runtime (e.g. node24) |
NUXT_HUB_SANDBOX_TIMEOUT |
Timeout ms |
NUXT_HUB_SANDBOX_CPU |
vCPU count |
NUXT_HUB_SANDBOX_PORTS |
Comma-separated ports |
NUXT_HUB_SANDBOX_ID |
Cloudflare sandbox ID |
NUXT_HUB_SANDBOX_CF_SLEEP_AFTER |
Cloudflare sleepAfter |
NUXT_HUB_SANDBOX_CF_KEEP_ALIVE |
true / false |
NUXT_HUB_SANDBOX_CF_NORMALIZE_ID |
true / false |
You can configure sandbox defaults in nuxt.config.ts and override per request via
hubSandbox(options).
export default defineNuxtConfig({
hub: {
sandbox: {
provider: 'vercel', // or 'cloudflare'
runtime: 'node24', // Vercel only
timeout: 300000, // ms
cpu: 2, // Vercel only
ports: [3000], // Vercel only
sandboxId: 'demo', // Cloudflare only
cloudflare: {
sleepAfter: 600,
keepAlive: true,
normalizeId: true,
},
},
},
})hubSandbox(options) accepts the same shape at runtime. For Cloudflare, you can
also pass namespace to override the Durable Object binding (it is auto-injected
when running on Workers).
provider:vercelorcloudflare(omit for auto-detect)runtime: Vercel runtime (e.g.node24)timeout: execution timeout (ms)cpu: Vercel CPU allocationports: Vercel exposed portssandboxId: Cloudflare sandbox identifiercloudflare.sleepAfter: idle timeout (seconds)cloudflare.keepAlive: keep sandbox warmcloudflare.normalizeId: normalize sandbox IDs
- Local development requires OIDC tokens (
vercel link+vercel env pull). - Longer timeouts and CPU/port limits depend on your Vercel plan.
- Sandboxes run as Durable Objects and sleep after idle (
sleepAfter). normalizeIdmay change sandbox IDs if you previously used mixed-case IDs.
GET /api/health— provider detection, availability, resolved configGET /api/sandbox— basic exec + file operationsGET /api/sandbox/features— provider-specific checksGET /api/sandbox/stream— streaming stdout/stderrGET /api/sandbox/process— background process + log wait
import { hubSandbox } from 'hub:sandbox'
export default defineEventHandler(async () => {
const sandbox = await hubSandbox()
try {
const exec = await sandbox.exec('echo', ['hello'])
await sandbox.writeFile('/tmp/test.txt', 'content')
const content = await sandbox.readFile('/tmp/test.txt')
return { exec, content }
}
finally {
await sandbox.stop()
}
})Playground UX and feature coverage mirror the local reference at:
~/unjs/unagent