Pause and resume
A full pause saves both the filesystem and memory of a sandbox. Running processes and in-memory state continue from the same point after resume.
mjs
import { Sandbox } from "@abox-dev/sdk";
const sandbox = await Sandbox.create();
try {
await sandbox.files.write("/tmp/session.txt", "saved session");
const process = await sandbox.commands.run("sleep 600", { background: true });
await sandbox.pause();
await sandbox.connect();
console.log(await sandbox.files.read("/tmp/session.txt"));
const status = await sandbox.commands.run(
`kill -0 ${process.pid} 2>/dev/null && printf 'process restored'`,
);
console.log(status.stdout);
} finally {
await sandbox.kill();
}The sandbox keeps its ID while paused. Save that ID in your application and pass it to Sandbox.connect when work needs to continue. Calling connect on a paused sandbox resumes it; calling it on a running sandbox returns another handle to the same environment.
Connections from your application to commands, PTYs, or services inside the sandbox close during pause. Reconnect them after the sandbox resumes.
If only files need to survive, use a filesystem-only pause. To create reusable copies instead of resuming the same ID, use snapshots.