Sandboxes
A sandbox is an instance with the sandbox plugin attached: a microVM that runs the commands you give it, and that you move files in and out of.
The Sandbox class wraps the plugin, so you write none of that by hand.
Your first sandbox
Code
Sandbox.create() reads the token from UKC_TOKEN.
With nothing else set, it boots debian-slim:latest with 2 GiB of memory in the default metro.
Configuration lists what you can change.
await using deletes the sandbox when the scope ends, even if the scope throws.
It needs TypeScript 5.2 or newer, or a runtime with explicit resource management.
Without it, call sandbox.delete() yourself.
Write a file and run it
Write a script into the sandbox, run it, and check the exit code before you trust the output:
Code
The instance underneath
A sandbox is a real instance, so the whole platform API still applies to it.
sandbox.instance is a handle on that instance:
Code
sandbox.uuid and sandbox.metro identify the instance.
sandbox.api is the raw plugin API, pinned to this sandbox.
Two ways in
Sandbox.create() builds its own client from the options you give it.
A client that you already hold opens the same door through ukc.metro("fra").sandboxes, and spends no second token:
Code
sandboxes belongs to a metro client, not to ukc, because a sandbox lives in exactly one metro.
Next steps
- Configuration: the image, the memory, the metro, snapshots, and your own plugin.
- Commands: run a command to completion, or start one and control it.
- Files: read, write, and upload files.
- Existing sandboxes: reconnect from another process, and list sandboxes.
examples/sandbox.ts: a complete program.- Sandboxes: what the platform underneath gives a sandbox.