Sandboxes
Create, execute, transfer files, pause, resume and reclaim a hardware-isolated guest.
Set COREVELOS_API_URL and COREVELOS_API_KEY as shown in the quickstart.
The free trial covers one regular sandbox plus one separate Velos agent sandbox, each up to 2 vCPU and 2 GiB RAM. Velos does not count toward the regular sandbox limit. Paused sandboxes retain their respective slots. Additional or larger resources need paid credit; Billing explains how free and paid credit work together.
Lifetime and commands
import { Sandbox } from "@corevelos/sdk";
const box = await Sandbox.create({ template: "corevelos-base", timeoutSeconds: 300 });
try {
const result = await box.commands.run("echo hello", { timeoutMs: 30_000 });
console.log(result.exitCode, result.stdout, result.stderr);
} finally { await box.kill(); }timeoutSeconds is the requested customer runtime, subject to finite tier limits.
Explicit timeoutSeconds: -1 requests unlimited customer lifetime while the wallet
remains funded. Funding authorization stays finite and is independently enforced.
Unlimited runtime is not permanent storage or guaranteed uptime.
Background commands
const { pid } = await box.commands.runInBackground("python -u worker.py", {
timeoutMs: 120_000,
});
for await (const event of box.commands.streamOutput(pid)) {
console.log(event);
}Background output is retained by the API process that started the command. Use the supported deployment routing; reconnecting after process replacement may require retrieving application logs from your workload instead.
Files
await box.files.makeDir("/home/user/app");
await box.files.write("/home/user/app/main.py", "print('hello')");
const content = await box.files.read("/home/user/app/main.py");
const entries = await box.files.list("/home/user/app");Pause and resume
await box.pause();
await box.resume();
// From a separate client process, reconnect by the saved sandboxId first:
const existing = Sandbox.connect(savedSandboxId);
await existing.resume();Pause preserves guest memory and stops vCPU/RAM billing. Retained storage remains billable. Running and paused resources can be reclaimed for insufficient funding according to the wallet's retention policy. Resume speed depends on workload and host.
Fork, snapshots, and rollback
const child = await box.fork({ timeoutSeconds: 300 });
const snap = await box.createSnapshot({ name: "before-migration" });
// Later, restore this sandbox to the snapshot in place:
await box.rollback(snap.snapshotId);Fork creates an independent child sandbox from the parent's current state, so
parallel agents can branch off one prepared machine. A snapshot captures the
whole MicroVM, memory, processes, and disk, and it outlives the sandbox: delete
it through Snapshots when nothing references it, or its storage keeps
metering. Rollback replaces the running state wholesale, so reconnect your
handles afterwards.
Preview URLs
const publicBox = await Sandbox.create({ template: "corevelos-base", exposure: "public" });
const url = await publicBox.getPreviewUrl(3000, { path: "/index.html" });Exposure is fixed at create and cannot change later. public ports answer
their URL directly; restricted ports, the default, answer 403 until the
request also carries the traffic token from getPreviewInfo().
Network egress
Sandboxes reach the public internet by default, but not your infrastructure:
guest-to-host traffic needs an explicit policy entry. Read the last applied
policy with getNetworkPolicy(), then replace it with setNetworkPolicy(),
which takes the complete desired state rather than merging with the old one.
Cost and logs
const cost = await box.getCost();
const metrics = await box.getMetrics();
const logs = await box.getLogs({ limit: 200 });getCost() reports the sandbox's whole-life cost for exact per-run
accounting; getMetrics() reads live CPU, memory, and disk; getLogs()
pages the sandbox log. The CLI equivalents are sandbox get --cost,
sandbox metrics, and sandbox logs.
Cleanup
await box.kill();Kill reclaims that guest and stops its future guest usage. Separately retained snapshots and volumes have their own lifecycle and charges; reclaim them explicitly when no longer needed. A sandbox belongs to one project.