Write a script that uses a sandbox with the TypeScript SDK.
Before you start
- Your workspace needs a plan or a trial. See Choose a plan or start a trial.
- You need an API key with the
sandboxes:read,sandboxes:write,sandboxes:exec,sandboxes:files, andsandboxes:sshscopes. See API keys. - You need Bun to run the script.
- For the SSH step, you need OpenSSH and an SSH key in
~/.ssh/id_ed25519. To make a key, runssh-keygen -t ed25519.
1
Install the SDK
Install the package, and put your API key in the
VMS_API_KEY environment variable.2
Create a sandbox and wait until it runs
Save this code in
sandbox.ts. waitUntilRunning reads the sandbox until its state is running.TypeScript
3
Run a command
Add this code.
exec gives each event of the command while it runs. wait gives the full output and the exit code.TypeScript
4
Write files
Add this code.
writeFiles sends all files in one tar upload.TypeScript
5
Connect with SSH
Add this code.
ssh adds your public key to the sandbox, then runs ssh with the host key of ssh.vms.dev. Leave out command to open a shell.TypeScript
6
Delete the sandbox
Add this code, then run
bun sandbox.ts.TypeScript
Check the result
The script prints the sandbox ID andrunning, the output of uname -a, exit code 0, hello, and the name of the sandbox. Then the script deletes the sandbox.
If a call fails, the SDK throws a VmsError with the HTTP status and the error code, such as no_capacity. See the SDK reference.