GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Sandbox

Run code in an isolated cloud machine on Vercel or Cloudflare, and get the result in your route.

server/sandbox-tasks/pixels/index.tsSame on every host
type ImageSize = { width: number, height: number }

// This runs in its own isolated machine.
// It is a normal function, with no special imports.
export default async function count(
  { width, height }: ImageSize,
) {
  return { pixels: width * height }
}
server/sandbox-tasks/pixels/index.ts
Deploy on

Vercel: Vercel Sandbox

A folder is a Sandbox Task

Put a package.json and index.ts in a folder under server/sandbox-tasks. The folder name is the task name.

Plain code and npm packages

The entry point is a standard async function. Its dependencies install in the Sandbox, not in your app.

Call it from a route

runSandboxTask() sends the input and returns [error, data]. Your function sets the input and result types.

Time limits and clear errors

Set a timeout in package.json. Failed or timed-out runs return an error status.

Vercel or Cloudflare

Choose the Driver in your config. The task code stays the same.

Know what the code can reach

Task code can use the network and files the provider allows. Limit them in provider settings.