Skip to content

Connect to a sandbox

Save a sandbox ID when the environment must outlive one request or process. Sandbox.connect creates a new SDK handle for that ID, so another worker can continue using the same environment.

mjs
import { Sandbox } from "@abox-dev/sdk";

const original = await Sandbox.create();

try {
  const connected = await Sandbox.connect(original.sandboxId);
  const result = await connected.commands.run("printf 'connected sandbox'");
  console.log(result.stdout);
} finally {
  await original.kill();
}

Connecting to a running sandbox does not create a copy. Both handles control the same sandbox and the same files and processes. Connecting to a paused sandbox resumes it first.

If your application no longer stores the ID, use Sandbox.list with a narrow metadata filter instead of selecting an arbitrary item from the project.