Skip to content
Dashboard

Automatic persistence now in beta on Vercel Sandbox

Link to headingHow it works

import { Sandbox } from '@vercel/sandbox';
// Create a named sandbox
const sandbox = await Sandbox.create({ name: 'user-a-workspace' });
await sandbox.runCommand('npm', ['install']);
await sandbox.stop();
// Later, resume where you left off
const sandbox = await Sandbox.get({ name: 'user-a-workspace' });
await sandbox.runCommand('npm', ['run', 'dev']);

const sandbox = await Sandbox.create({ name: "long-lived-sandbox" });
await sandbox.writeFiles([{
path: "run.sh",
content: Buffer.from('#!/bin/bash\necho "Hello!"'),
mode: 0o755,
}]);
// Days later
const resumedSandbox = await Sandbox.get({ name: "long-lived-sandbox" });
console.log(resumedSandbox.status); // stopped automatically
await resumedSandbox.runCommand("./run.sh"); // logs "Hello!"
console.log(resumedSandbox.status); // running

const sandbox = await Sandbox.get({ name: 'user-alice' });
// Scale up resources on a running sandbox
await sandbox.update({ resources: { vcpus: 4 } });
// Inspect session history and snapshots
const { sessions } = await sandbox.listSessions();
const { snapshots } = await sandbox.listSnapshots();
// Search across sandboxes
const { sandboxes } = await Sandbox.list({
namePrefix: 'user-',
sortBy: 'name',
});
// Permanently remove a sandbox and all its data
await sandbox.delete();

# Spin up a sandbox for a user
sandbox create --name user-alice
# User runs commands — if the sandbox timed out, it resumes automatically
sandbox run --name user-alice -- npm test
# Check what happened across sessions
sandbox sessions list user-alice
# Tune resources without recreating
sandbox config vcpus user-alice 4
sandbox config timeout user-alice 5h

Ready to deploy?