Sandbox quickstart
Start a sandbox, run code in it and stop it
This starts a machine, writes a Python file to it, runs it and stops the machine. It costs about a cent.
Create a sandbox
import Zavudev from "@zavudev/sdk"; const zavu = new Zavudev({ apiKey: process.env["ZAVUDEV_API_KEY"], // This is the default and can be omitted }); const { sandbox } = await zavu.sandboxes.create({ size: "default", timeoutSeconds: 1800, idempotencyKey: "build-1042", }); console.log(sandbox.id, sandbox.status); // "starting"The answer is
202with the sandbox instarting. You do not need to wait forrunning: commands and file calls made while it starts wait for it.Retrying with the same
idempotencyKeyanswers409with the sandbox the first request created, instead of starting and charging a second one.Write a file and run it
await zavu.sandboxes.files.write(sandbox.id, { path: "main.py", content: "print(2 + 2)\n", }); const { result } = await zavu.sandboxes.commands.run(sandbox.id, { command: "python3 main.py", }); console.log(result?.exitCode, result?.stdout); // 0 "4\n"JSON{ "result": { "exitCode": 0, "stdout": "4\n", "stderr": "", "stdoutTruncated": false, "stderrTruncated": false, "timedOut": false, "startedAt": "…", "finishedAt": "…" } }Stop it
await zavu.sandboxes.stop(sandbox.id);Billing ends here. The disk is kept 14 days: resume it with
zavu.sandboxes.resume(id), or delete it for good withzavu.sandboxes.delete(id).
Next
- Commands and files: long-running commands and binary files.
- Ports, SSH and the desktop: reach what runs inside.
- Snapshots and environments: start the next sandbox ready to work.