Skip to content

exe.dev Rust SDK

Everything ssh exe.dev does, from Rust, with Tokio or blocking calls.

exedev is exe.dev's official Rust SDK. Everything ssh exe.dev does is a method: create and copy VMs, run commands and stream their output, move files, share what a VM serves, make tokens, and attach integrations.

#[tokio::main]
async fn main() -> exedev::Result<()> {
    let exe = exedev::Client::from_env()?; // reads EXE_TOKEN

    let vm = exe.new_vm().await?; // returns once the VM accepts commands
    let r = vm.run("uname -sr").check(true).await?;
    print!("{}", r.stdout_lossy());
    println!("{}", vm.https_url());
    vm.delete().await?;
    Ok(())
}
$ cargo run -q
Linux 6.12.115
https://jade-loader.exe.xyz

That program took 2.6 seconds, VM creation and deletion included. Every method returns a builder: set options, then .await it. Everything below was compiled and run against exe.dev with exedev 0.1.0 on Rust 1.100.0 (source and changelog).

Install and get a token#

cargo add exedev
cargo add tokio --features full

Make a token on your computer with only the commands your program needs:

ssh exe.dev ssh-key generate-api-key --label=my-tool --tag=my-tool --exp=30d \
  '--cmds="new,ls,ssh,rm,cp,pause,resume,restart,resize,comment,share show,share set-public,share set-private,share add-link"'
export EXE_TOKEN=exe1.…   # or exedev::Client::new(token)

Keep ssh (run() and new_vm() use it) and rm; the default set has neither. With --tag, the token sees and manages only VMs with that tag, and VMs it creates get it. Leave the tag off only for account-wide work (integrations, billing). Revoke it with ssh exe.dev ssh-key remove my-tool.

Your first program#

use tokio::io::{AsyncBufReadExt, BufReader};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let exe = exedev::Client::from_env()?;
    let vm = exe.new_vm().comment("first program").await?;

    let result = serve(&vm).await; // whatever happens there,
    vm.delete().await?; // delete the VM
    result
}

async fn serve(vm: &exedev::Vm) -> Result<(), Box<dyn std::error::Error>> {
    vm.write_file("site/index.html", "<h1>Hello from Rust</h1>\n").await?;
    vm.spawn("python3 -m http.server 8000").name("web").cwd("site").await?;
    let page = vm.run("curl -s --retry 9 --retry-connrefused localhost:8000").check(true).await?;
    print!("{}", page.stdout_lossy());
    println!("serving at {}", vm.https_url());

    println!("Open it, then press Enter to delete the VM");
    BufReader::new(tokio::io::stdin()).lines().next_line().await?;
    Ok(())
}

Dropping a Vm doesn't delete the VM, so the work happens in serve() and main() deletes the VM whatever it returned. The URL is private: only you, signed in to exe.dev, can open it until you share it.

Without async, use the blocking feature (cargo add exedev --features blocking) and write .block_on() where async code writes .await:

use exedev::blocking::BlockOn as _;

fn main() -> exedev::Result<()> {
    let exe = exedev::Client::from_env()?;
    let vm = exe.new_vm().block_on()?;
    print!("{}", vm.run("uname -sr").block_on()?.stdout_lossy());
    vm.delete().block_on()?;
    Ok(())
}

Create and manage VMs#

new_vm() takes the flags of ssh exe.dev new:

use exedev::WaitUntil;

let vm = exe
    .new_vm()
    .cpu(2).memory("4GB").disk("25GB")
    .env("APP_ENV", "staging") // set for every command
    .comment("staging for #1234")
    .setup_script("#!/bin/bash\nset -e\nsudo apt-get install -y -q jq\n")
    .wait_until(WaitUntil::Setup) // also wait for the setup script
    .await?;

Also: .image() and .registry_auth() for a custom image, .tags() (not with a --tag token), .integrations(), .egress(), .prompt() for the VM's agent, Shelley, and .standalone(true) for a standalone VM. A failing setup script is Error::VmNotReady with the script's exit code and output, and the VM is deleted unless you set .keep_on_failure(true).

for v in exe.vms().pattern("preview-*").await? {
    println!("{} {} {:?}", v.name(), v.status(), v.tags());
}

let mut vm = exe.vm("my-app").await?;
vm.set_comment("kept for debugging").await?;
vm.rename("my-app-old").await?; // name() and https_url() follow
vm.resize().cpu(4).memory("8GB").disk("50GB").restart(true).await?;
let copy = vm.copy().await?; // a new VM with a copy of the disk
vm.restart().await?; // waits until it accepts commands again
vm.pause().await?; // frees CPU and memory; processes survive
vm.resume().await?;
exe.delete([vm.name(), copy.name()]).await?; // or vm.delete()

In our tests a copy took 1.9 seconds, restart() 2.2, pause() 2.2, and resume() 0.8. copy(), pause(), and restart() flush the VM's writes to disk first. A Vm's getters are a snapshot; vm.refresh() updates them.

Run commands and stream output#

run() runs a command in a bash login shell as the exedev user (with sudo), in the home directory:

let r = vm.run("echo $APP_ENV; exit 3").await?; // r.exit_code == 3, r.stdout_lossy() == "staging\n"
vm.run(["python3", "-c", code, "it's me"]).await?; // an argument list, quoted for you
vm.run("cargo test").cwd("app").env("CI", "1").check(true).await?; // Err(Error::Command) if it fails

vm.run("cargo build --release")
    .on_stdout(|line| println!("{line}")) // line by line, as it arrives
    .on_stderr(|line| eprintln!("{line}"))
    .await?;

on_stdout_bytes() gets raw bytes, and .capture(false) keeps nothing in memory. Output past 8 MiB (or .max_output(n)) is Error::Interrupted.

Warning

In 0.1.0, run().timeout(...) returns an error on time, but the command keeps running on the VM, and so does one whose future you drop. Bound it on the VM too: vm.run("timeout 60 cargo test").

For servers and long jobs, spawn() starts a process that outlives the request and your program:

let mut job = vm.spawn("./build.sh").name("build").await?;
job.poll().await?; // None while it runs
print!("{}", job.logs().tail(20).await?.stdout_lossy());
let result = job.wait().timeout(Duration::from_secs(3600)).check(true).await?;

exe.vm("my-app").await?.process("web").await?.terminate().await?; // from any program, later

Processes survive pause() but not restart() (Error::ProcessLost). For a service that should survive reboots, write a systemd unit.

Move files#

vm.write_file("app/config.json", json).await?; // &str, String, or Vec<u8>
vm.write_file("bin/run.sh", script).mode(0o755).await?;
let data: Vec<u8> = vm.read_file("app/out.csv").await?; // Error::FileNotFound if missing
vm.upload("./src", "app").exclude([".git", "target", "*.log"]).await?;
vm.download("app/dist", "./dist").await?; // a file or a directory

Paths are relative to the home directory. 3 MB took 0.6 seconds each way; for big files, have the VM fetch them or use scp.

Share a VM and reach it from code#

The HTTPS proxy serves port 8000 at vm.https_url() and ports 3000-9999 at vm.url(Some(3000), "/")?, privately until you share:

vm.share().set_public().await?; // set_private() undoes it
vm.share().add("ana@example.com").message("Have a look").await?;
let link = vm.share().add_link().await?.url; // a link that lets whoever opens it sign in

People you share with sign in to exe.dev, and your app gets their address in the X-ExeDev-Email header. For code calling a private VM, make a VM token, here with reqwest:

let vm_token = exe.ssh_key().generate_api_key().vm(vm.name()).label("api-client").exp("7d").await?.token;

let r = reqwest::Client::new()
    .get(vm.url(Some(8000), "/health")?)
    .header("X-Exedev-Authorization", format!("Bearer {vm_token}"))
    .send()
    .await?;
println!("{}", r.status()); // 200; 401 without the token

A VM token opens one VM's HTTPS endpoints and can't run exe.dev commands. It also works as a Basic auth password, for tools like git.

Tokens and keys#

let ci_token = exe.ssh_key().generate_api_key()
    .label("ci").tag("ci").exp("30d")
    .cmds(["new", "ls", "ssh", "rm"])
    .await?.token;
exe.ssh_key().add(public_key).vms(["web", "db"]).await?; // SSH to two VMs, nothing else
exe.ssh_key().remove("ci").await?; // revokes it

A token can't hand out more than it has. With .tag(format!("customer-{id}")), each customer's token sees only its own VMs. See VM-scoped SSH keys.

exedev::sign_token() makes tokens locally, with no request, by signing with an SSH key on your account through ssh-keygen -Y sign (local key creation):

let api_token = exedev::sign_token("~/.ssh/exe_dev_api")
    .cmds(["ls"]).expires_in(Duration::from_secs(3600)).sign()?;
let vm_token = exedev::sign_token("~/.ssh/exe_dev_api")
    .vm("my-app").expires_in(Duration::from_secs(3600)).sign()?;

The token can do no more than its key, and removing the key revokes every token it signed.

Egress and integrations#

vm.set_egress(EgressPolicy::Integrations) (or .egress(...) on new_vm()) cuts a VM off from the internet, except for its integrations: curl https://example.com then fails with "Could not resolve host". EgressPolicy::All undoes it.

Integrations keep secrets off the VM: exe.dev adds them to requests the VM makes to https://<name>.int.exe.xyz. Managing them takes a token without --tag:

exe.integrations().add("http-proxy").name("stripe")
    .target("https://api.stripe.com").bearer(stripe_key).await?;
exe.integrations().attach("stripe", format!("vm:{}", vm.name())).for_duration("2h").await?;

Code on the VM then calls https://stripe.int.exe.xyz/v1/... with no key. In our test, the target received the Authorization header and the VM never saw it. See the HTTP proxy integration and the keyless LLM gateway.

Everything else#

Every other command is a method, grouped as on the command line, with its help as its docs.rs documentation: exe.billing().usage().group("vm").range("7d"), exe.team().members(), exe.pool().list(), vm.share().port().port(3000). Results with a known shape are types in exedev::types; the rest are serde_json::Value. For a command with no method yet:

let info = exe.exec(&format!("stat {}", exedev::quote(vm.name()))).await?;

If you build a tool on the SDK, name it in the User-Agent:

let exe = exedev::Client::builder()
    .user_agent("nightly-copy/1.0") // sends "nightly-copy/1.0 exedev-rust/0.1.0"
    .build()?; // still reads EXE_TOKEN

Recipes#

Copy a VM every night#

Copy a VM, pause the copy so it uses no CPU or memory, and keep the last seven (cargo add chrono):

use chrono::Utc;

const SOURCE: &str = "my-app";
const KEEP: usize = 7;

#[tokio::main]
async fn main() -> exedev::Result<()> {
    let exe = exedev::Client::builder().user_agent("nightly-copy/1.0").build()?;
    let source = exe.vm(SOURCE).await?;

    let stamp = Utc::now().format("%Y%m%d-%H%M");
    let mut copy = source.copy().name(format!("{SOURCE}-{stamp}")).await?;
    copy.pause().await?;
    println!("copied {SOURCE} to {}", copy.name());

    let prefix = format!("{SOURCE}-");
    let mut copies: Vec<_> = exe.vms().pattern(format!("{prefix}*")).await?
        .into_iter()
        .filter(|vm| vm.name()[prefix.len()..].starts_with(|c: char| c.is_ascii_digit()))
        .collect();
    copies.sort_by(|a, b| a.name().cmp(b.name()));
    for vm in &copies[..copies.len().saturating_sub(KEEP)] {
        vm.delete().await?;
        println!("deleted {}", vm.name());
    }
    Ok(())
}

Run it from cron or a scheduled CI job with a token that has ls, cp, ssh, pause, and rm. To restore, resume a copy: ssh exe.dev resume my-app-20261124-0300. For backups outside exe.dev, see VM backups.

Fan a job out over many VMs#

Prepare one VM, copy it eight times in parallel, give each copy a share of the work, and delete them all:

use std::time::Duration;

use exedev::Vm;
use tokio::task::JoinSet;

const N: usize = 8;

// Counts the primes in this worker's share of 1..20,000,000.
const WORK: &str = r#"
import sys
i, n = int(sys.argv[1]), int(sys.argv[2])
lo, hi = i * 20_000_000 // n, (i + 1) * 20_000_000 // n
sieve = bytearray([1]) * hi
sieve[0:2] = b"\0\0"
for p in range(2, int(hi ** 0.5) + 1):
    if sieve[p]:
        sieve[p * p::p] = bytes(len(range(p * p, hi, p)))
print(sum(sieve[lo:hi]))
"#;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let exe = exedev::Client::from_env()?;
    let base = exe.new_vm().comment("fan-out").await?;
    let result = fan_out(&base).await;
    base.delete().await?;

    let mut total = 0;
    for out in result? {
        total += out.trim().parse::<u64>()?;
    }
    println!("{total} primes below 20,000,000");
    Ok(())
}

async fn fan_out(base: &Vm) -> exedev::Result<Vec<String>> {
    base.write_file("work.py", WORK).await?; // copies inherit the base's disk

    let mut tasks = JoinSet::new();
    for i in 0..N {
        let base = base.clone();
        tasks.spawn(async move {
            let vm = base.copy().await?;
            let run = vm
                .run(format!("timeout 600 python3 work.py {i} {N}"))
                .check(true)
                .timeout(Duration::from_secs(660))
                .await;
            vm.delete().await?; // whatever happened to the run
            Ok(run?.stdout_lossy())
        });
    }
    // Wait for every worker, so each deletes its VM, then report the first error.
    let mut results = Vec::new();
    while let Some(done) = tasks.join_next().await {
        results.push(done.expect("worker panicked"));
    }
    results.into_iter().collect()
}
$ time cargo run -q --release
1270607 primes below 20,000,000

real	0m6.435s

Nine VMs made, used, and deleted in 6.4 seconds. Install packages and clone repositories on the base, once, and every copy has them. Copies share your plan's CPU and count toward its VM limit; for capacity of their own, create the base with .standalone(true) (see Sandbox).

Errors#

Every error is an exedev::Error. The ones you'll match on:

  • Api: exe.dev refused the command; .kind() is Authentication, PermissionDenied, NotFound, RateLimited, VmNotRunning, or Other. Rate-limited requests are retried 5 times first.
  • Command: run().check(true) and the command failed.
  • Interrupted: timeout, output limit, or a dropped connection; the command may still be running.
  • Network: the request failed; whether it took effect is unknown.
  • VmNotReady, ProcessLost, FileNotFound.

e.is_not_found(), e.is_permission_denied(), and e.is_timeout() save a match. Messages never include the token or the command.

Keep tokens in CI secrets or a secret manager, never on a VM other people or untrusted code can reach. For more recipes (a preview VM per pull request, a cleanup job, LLM agent tools), see the Python SDK; they translate directly.

Frequently asked questions#

What does it need?

Rust 1.88 or later and Tokio. It uses reqwest with rustls, so there is no OpenSSL to install. Tested with exedev 0.1.0 on Rust 1.100.0. exedev = "0.1" takes fixes but never 0.2, where the API may change.

Does dropping a Vm delete the VM?

No; call vm.delete(). Only new_vm() cleans up on its own: if the VM doesn't become ready, or the future is dropped while it waits, the SDK deletes it.

Is it the same API as ssh exe.dev?

Yes. It is generated from exe.dev's command tree and calls the HTTPS API: ssh exe.dev team members is exe.team().members(), and --copy-tags=false is .copy_tags(false).

SDK or MCP?

The SDK when your code decides what happens (CI, cron, a service that gives each user a VM); exe.dev MCP when a model decides.

Are there SDKs for other languages?

Yes, with the same commands: Python and TypeScript.

Published Nov 25, 2026 · Updated Nov 25, 2026 · tested end to end Nov 25, 2026 · Markdown · manifest.json · Something wrong? Tell us