@vite-hub/sandbox
v0.0.1
Published
Sandbox execution primitives and Vite integration for ViteHub.
Maintainers
Readme
@vite-hub/sandbox
@vite-hub/sandbox runs typed work in an isolated provider runtime without coupling callers to that provider.
Install
pnpm add @vite-hub/sandboxAdd @cloudflare/sandbox or @vercel/sandbox for the provider you use.
Minimal API
// server/sandboxes/release-notes.ts
import { defineSandbox } from "@vite-hub/sandbox"
export default defineSandbox(async (payload: { notes?: string } = {}) => {
return {
summary: payload.notes?.split("\n")[0] ?? "",
}
})// server/api/release-notes.post.ts
import { runSandbox } from "@vite-hub/sandbox"
import { defineEventHandler, readBody } from "h3"
export default defineEventHandler(async (event) => {
const result = await runSandbox("release-notes", await readBody(event))
return result.isOk() ? result.value : { error: result.error.message }
})// nitro.config.ts
import { defineNitroConfig } from "nitro/config"
export default defineNitroConfig({
modules: ["@vite-hub/sandbox/nitro"],
sandbox: { provider: "cloudflare" },
})Vite and Nitro
Nitro discovers server/sandboxes/<name>.ts. Vite also supports src/<name>.sandbox.ts through hubSandbox(). Provider config selects Cloudflare Sandbox SDK or Vercel Sandbox.
Learn more at vitehub.dev.
