Skip to main content

Crate dvm_run

Crate dvm_run 

Source
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.
CommandBuilder
A command to run: Commands::run or Commands::spawn, then how it starts; awaited, its result or a handle to it.
CommandHandle
A command spawned in the background.
CommandResult
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.
LoggedIn
A login’s key, which save_key keeps where the SDK finds it.
Replay
A replay of an execution.
ReplayBuilder
A replay to start: Execution::replay; awaited, the replay.
Sandbox
A sandbox, from Client::create_sandbox or Client::connect_sandbox. It runs until Sandbox::stop: dropping it doesn’t stop it.
SandboxBuilder
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.
WaitForCommand
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§

DEFAULT_API_URL

Functions§

credentials_path
Where the keys are saved.
login
Logs this machine in to dvm.run at api_url, else DVM_API_URL, else https://sandbox.dvm.run, once its user approves the login in their browser: the key it was given. say is told what to do; with open_browser, the page that approves it opens here.
save_key
Saves key for the dvm.run at api_url, in place of the one saved for it before; the file it’s in.

Type Aliases§

OutputCallback
Called with each piece of a stream’s output, as text, as it’s written.
Result