const sb = await client.sandbox({
image: "node:22",
resources: {
cpu: "500m",
memory: "256Mi",
},
});
const { stdout } = await sb.exec(
"node index.js",
);
// stream live output
await sb.exec("npm test")
.pipe(process.stdout);
await sb.writeFile("/app/main.py", src);
const logs = await sb.readFile(
"/var/log/app.log",
);
const entries = await sb.listDirectory(
"/app", { depth: 1 },
);
await sb.checkpoint("before-tests");
// restore exact state later
const resumed = await client.resume(
sandboxId,
);
await resumed.exec("npm test");
await sb.checkpoint();
const fork = await sb.fork();
// two independent containers, same state
await Promise.all([
sb.exec("npm test -- --shard=1/2"),
fork.exec("npm test -- --shard=2/2"),
]);
const env = client.environment("ci", {
image: "node:22",
resources: { cpu: "500m", memory: "512Mi" },
setup: async (sb) => {
await sb.exec("npm ci");
},
});
// builds once, restores from snapshot
const sb = await env.sandbox();
await sb.exec("npm test");
const sessions = await client.sandboxes.list({
status: SandboxStatus.Running,
limit: 20,
});
const details = await client.sandboxes.get(
"ci", sandboxId,
);
// { status, execCount, startedAt }