lightbox

Sandbox pool

Boot many sandboxes from the same snapshot in parallel.

The whole point of snapshots is that boot is cheap. Launching N sandboxes in parallel takes about as long as launching one.

import { launchSandbox } from "@beamhop/lightbox";

await Promise.all(
  ["agent-1", "agent-2", "agent-3"].map(async (name) => {
    const sb = await launchSandbox({ snapshot: "lightbox", name });
    await sb.detach();   // let each VM outlive this script
  }),
);

console.log("all three running");

Address them later by name from any process:

import { connectToSandbox } from "@beamhop/lightbox";

const results = await Promise.all(
  ["agent-1", "agent-2", "agent-3"].map(async (name) => {
    const sb = await connectToSandbox(name);
    const r = await sb.shell("hostname");
    return { name, host: r.stdout().trim() };
  }),
);

console.log(results);