Expand description
dvm.run’s Rust SDK: sandboxes whose every run replays.
A sandbox is a VM made from an image: your agent sends it commands and files until it stops it. Everything it ran is its execution, which replays, the same, once it ends.
use std::time::Duration;
let client = dvm_run::Client::from_env()?;
let sbx = client.create_sandbox("python:3.12").seed(7).await?;
sbx.files().write("/app/main.py", "print(1 + 1)\n").await?;
let r = sbx
.commands()
.run("python main.py")
.cwd("/app")
.timeout(Duration::from_secs(60))
.await?;
println!("{} {}", r.stdout, r.exit_code);
let server = sbx.commands().spawn(["python", "-m", "http.server"]).await?;
server.kill().await?;
server.wait().await?;
sbx.stop().await?;
let verdict = client.execution(sbx.id()).await?.replay().await?.wait().await?;
assert!(verdict.is_same());Client::from_env takes dvm.run’s address from DVM_API_URL, else
https://sandbox.dvm.run, and its key from DVM_API_KEY, else the one
dvm-run login saved for that address. The API’s types are
dvm_api’s, here as api.
Re-exports§
pub use dvm_api as api;
Structs§
- Background
- Started, and a handle to it:
Commands::spawn. - Client
- dvm.run’s API, at an address, as the user whose key it bears. Cheap to clone: clones share their connections.
- Command
Builder - A command to run:
Commands::runorCommands::spawn, then how it starts; awaited, its result or a handle to it. - Command
Handle - A command spawned in the background.
- Command
Result - A command that exited: its output, and its exit code. A signal’s kill is code 128 and the signal, as a shell says, with the signal given.
- Commands
- A sandbox’s commands:
Sandbox::commands. - Execution
- A sandbox’s execution, from
Client::execution: its spec, its state, each command it was sent, as it ran, and its log’s size once it ended. - Files
- A sandbox’s files:
Sandbox::files. - Foreground
- Run to its exit, awaited:
Commands::run. - Logged
In - A login’s key, which
save_keykeeps where the SDK finds it. - Replay
- A replay of an execution.
- Replay
Builder - A replay to start:
Execution::replay; awaited, the replay. - Sandbox
- A sandbox, from
Client::create_sandboxorClient::connect_sandbox. It runs untilSandbox::stop: dropping it doesn’t stop it. - Sandbox
Builder - What a sandbox is made of:
Client::create_sandbox, then what differs from 1 vCPU, 1024 MiB, seed 0, the image’s variables, and a name after the image; awaited, the sandbox, once it’s running. - Wait
ForCommand - Waiting for a command, from
CommandHandle::wait; awaited, its result once it exits. Dropped, it stops the waiting, not the command.
Enums§
- Error
- What the SDK returns when a call fails. A command’s exit code is never one of these.
Constants§
Functions§
- credentials_
path - Where the keys are saved.
- login
- Logs this machine in to dvm.run at
api_url, elseDVM_API_URL, elsehttps://sandbox.dvm.run, once its user approves the login in their browser: the key it was given.sayis told what to do; withopen_browser, the page that approves it opens here. - save_
key - Saves
keyfor the dvm.run atapi_url, in place of the one saved for it before; the file it’s in.
Type Aliases§
- Output
Callback - Called with each piece of a stream’s output, as text, as it’s written.
- Result