01 / INSTALL
Create the runtime Worker
After the first npm release, use the initializer. A prebuilt
Wasm engine is included; no C++ or Wasm toolchain needed.
pnpm dlx @sandbox-workers/cli init javascript my-sandbox
cd my-sandbox
pnpm install
pnpm dry-run
pnpm run deploy
Choose a unique Worker name before deploying. The generated
Worker has no public URL. For now, install a local release
tarball as described in the repository README.
02 / BIND
Connect your application
Add this Service Binding to your application's
wrangler.jsonc. Both Workers belong to your
Cloudflare account.
{
"services": [{
"binding": "SANDBOX",
"service": "sandbox-javascript"
}]
}
The service name must match the deployed runtime Worker. Keep
your application's existing configuration.
03 / EXECUTE
Use the typed client
Install @sandbox-workers/core in your caller. The
client uses your binding directly.
import { createSandbox } from
"@sandbox-workers/core";
const js = createSandbox(env.SANDBOX);
const output = await js.runCode(
"const x = Number(process.env.X);\nx ** 2",
{ envVars: { X: "12" } },
);
// { results: [{ text: "144" }], ... }