Rust SDK
Give your agent, or your own code, a computer of its own. From async Rust on Tokio, create a sandbox on a Linux machine you own, run commands in it, move files in and out, then put it to sleep, snapshot it or fork it.
Install
On Rust 1.99 or later (edition 2024):
cargo add hermitbox tokio --features tokio/macros,tokio/rt-multi-threadThe SDK talks to a Hermitbox install. On the machine where you installed Hermitbox,
Hermitbox::new() connects by itself; anywhere else, set HERMITBOX_API_URL and
HERMITBOX_API_KEY. Hermitbox installs on Linux (x86_64 or aarch64) with one command, as your own
user: curl -fsSL https://hbx.sh | sh.
Quickstart
use hermitbox::Hermitbox;
#[tokio::main]
async fn main() -> hermitbox::Result<()> {
let hb = Hermitbox::new()?;
let sandbox = hb.sandbox().await?;
println!("{}", sandbox.run("echo hello").await?.stdout.trim());
sandbox.delete().await?;
Ok(())
}What you get
- Sandboxes on your own Linux machines, with no hosted service in between.
- Sleep keeps state. It stops a sandbox’s compute and keeps its files, and the next command wakes it. A suspended wake measured 27.56 ms at p50 in our budget checks.
- Five isolation tiers, from
processtovm, a Firecracker VM with its own kernel. Name one and you get it, or a refusal that says what is missing. - Python and JavaScript kernels, a headless browser, an X11 desktop and SSH on the same handle
(
sandbox.python(),sandbox.browser(),sandbox.desktop(),sandbox.ssh()).
Sleep and wake
Put a sandbox to sleep to release its compute while it keeps its data directory, then wake it:
use hermitbox::Hermitbox;
#[tokio::main]
async fn main() -> hermitbox::Result<()> {
let hb = Hermitbox::new()?;
let sandbox = hb.sandbox().await?;
let outcome = async {
sandbox.write("notes.txt", "still here").await?;
sandbox.sleep().await?;
sandbox.wake().await?;
println!("{}", sandbox.read("notes.txt").await?); // still here
Ok::<(), hermitbox::HermitboxError>(())
}
.await;
let _ = sandbox.delete().await;
outcome
}Reference
Every method on the client and its handles. These rules hold across all of them.
Durations (DurationSpec) accept std::time::Duration, positive seconds, or s, m, h, d
strings. String commands (Command::Shell / &str) use sh -c, and Vec<String> / &[&str]
(Command::Argv) bypasses the shell. Commands run in persistent storage unless cwd overrides it.
Paths are relative to persistent storage (/data). Binary data streams through the agent while the
sandbox runs and through the node while it is stopped. File operations need no shell tools.
Each call carries one generated idempotency key, and no mutation retries automatically. Output capture and observation queues are bounded: overflow is explicit, and the result stays available.
A missing exit is an unknown outcome, and a disconnect does not end the process. HermitboxError
keeps the status, code, details and trace ID. Credentials never enter Debug output or serialized
views.
Every handle is cheaply cloneable and safe to share across Tokio tasks. Methods taking options use
builder structs (SandboxOptions::new(), RunOptions::new(), StartOptions::new(), and so on)
so the common path needs no boilerplate.
| Method | Behavior |
|---|---|
Hermitbox::new() |
Connect using HERMITBOX_API_URL/HERMITBOX_API_KEY or the saved local config. |
Hermitbox::connect(url, key) |
Connect with an explicit API URL and project key. |
hb.sandbox() / hb.create_sandbox(options) |
Create with image, isolation, template, env, labels, name, workdir, user, auto_delete, egress, metadata or repo. |
hb.get_sandbox(id) / hb.sandbox_by_name(name) / hb.sandbox_by_name_with(name, wake) |
Look up an existing sandbox; wakes unless wake is false. |
hb.sandboxes(filters) |
Filter project handles by name, labels and state. |
hb.project() |
Project usage and limits. |
hb.run(image, command, options) |
Create, run and always delete the sandbox. |
sandbox.run(command) / sandbox.run_with(command, options) |
Start now and return the bounded RunResult. |
sandbox.stream(command) / sandbox.stream_with(command, options) |
Start eagerly on Tokio; iterate live Chunk items once via StreamExt. |
stream.lines() |
Iterate complete stdout/stderr lines. |
stream.result() |
Await the same command result without starting it again. |
sandbox.spawn(command) / sandbox.spawn_with(command, options) |
Start a background process; stdin accepts one-shot string or bytes. |
sandbox.start() |
Start sandbox compute. |
sandbox.stop() |
Stop compute; retain data. |
sandbox.sleep() |
Suspend or stop while retaining data. |
sandbox.wake() |
Resume or recreate compute. |
sandbox.rest() |
Archive data and release compute. |
sandbox.refresh() |
Refresh the view and invalidate its cached capability. |
sandbox.delete() |
Delete sandbox and owned data. |
sandbox.read(path) |
Read UTF-8 persistent data. |
sandbox.read_bytes(path) |
Read persistent bytes. |
sandbox.read_stream(path) |
Read a byte stream without collecting the file. |
sandbox.write(path, data) |
Write strings, bytes or byte streams. |
sandbox.snapshot() |
Create a snapshot handle. |
sandbox.snapshots() |
List snapshot handles. |
snapshot.fork() / snapshot.fork_with(options) |
Create a sandbox from the snapshot. |
snapshot.delete() |
Delete the snapshot. |
sandbox.endpoints() |
List assigned application endpoints. |
sandbox.events(options) |
Stream lifecycle records with since and follow. |
sandbox.logs(options) |
Read or follow logs, without waking a sleeping sandbox. |
sandbox.terminal(options) |
Open a PTY with optional rows and cols. |
sandbox.mcp_url() |
Scoped sandbox-local MCP URL. |
sandbox.expose(port) |
Publish a spare port and return its URL. |
sandbox.unexpose(port) |
Release an exposed spare. |
sandbox.network(mode) |
Replace compute with NetworkMode::Internet or NetworkMode::None. |
process.wait() |
Wait for its terminal status. |
process.events() |
Read agent output/exit frames. |
process.stream() |
Read decoded stdout/stderr chunks. |
process.lines() |
Read complete lines. |
process.stdin().write(data) |
Send string or bytes. |
process.stdin().close() |
Close input. |
process.signal(signal) |
Signal the process. |
process.kill() |
Kill the process. |
process.resize(cols, rows) |
Resize its PTY. |
terminal.stdin().write(data) |
Send terminal input. |
terminal.resize(cols, rows) |
Resize the terminal. |
terminal.signal(signal) |
Signal the terminal process. |
terminal.events() |
Read terminal frames. |
terminal.stream() |
Read terminal output. |
terminal.close() |
Close the terminal. |
files.read(path) |
Read UTF-8 text. |
files.read_bytes(path) |
Read bytes. |
files.read_stream(path) |
Stream bytes. |
files.write(path, data) |
Write persistent data. |
files.list(path) |
List directory entries. |
files.stat(path) |
Read file metadata. |
files.mkdir(path) |
Create directories. |
files.move_entry(source, target) |
Move a persistent entry. |
files.delete(path) |
Delete a persistent entry. |
files.watch(path) |
Ready frame, then bounded changes. |
files.url(path, method) |
Grant one file operation for at most one minute. |
files.upload(local, remote, options) |
Stream caller disk to the sandbox with progress callback. |
files.download(remote, local, options) |
Stream to caller disk with progress callback. |
sandbox.processes() |
List retained process handles. |
sandbox.kill_all() |
Signal all running processes once. |
process.wait_for_port(port, options) |
Await owned TCP or HTTP readiness; timeout and early exit differ. |
process.wait_for_log(pattern, timeout) |
Await a bounded regular expression match in either stream. |
process.wait_for_exit(timeout) |
Await exit with a deadline. |
process.logs() |
Read retained process stdout/stderr chunks. |
sandbox.shell(options) |
Open a persistent shell with cwd and env. |
shell.run(command) / shell.run_with(command, timeout) |
Run serially with exact separate streams and exit code. |
shell.close() |
Close and terminate that session. |
files.exists(path) |
Test existence without following links. |
files.find(glob) |
Find relative paths within the agent search budget. |
files.grep(pattern, options) |
Return path, line and matching text; paths scope the search. |
files.replace(pattern, text, options) |
Replace literal text at regex matches; preserve modes. |
files.chmod(path, mode) |
Set ordinary permission bits. |
files.upload_dir(local, remote, options) |
Stream a bounded tar; preserve files and empty directories. |
files.download_dir(remote, local, options) |
Extract a bounded tar; refuse links and traversal. |
sandbox.sync(local, remote) |
Upsert changed content by SHA-256; never delete. |
sandbox.git().clone_repo(url, options) |
Clone public/HTTPS repositories with path, branch, depth and token. |
sandbox.git().status() |
Parsed clean flag and entries, plus raw result. |
sandbox.git().diff(options) |
Parsed patch, optionally staged, plus raw result. |
sandbox.git().branch(name) |
List or create branches, plus raw result. |
sandbox.git().checkout(reference, options) |
Checkout or create a branch, plus raw result. |
sandbox.git().add(paths) |
Stage paths without shell interpolation. |
sandbox.git().commit(message, options) |
Commit with optional author; return hash and raw result. |
sandbox.git().push(options) |
Push with an optional one-call token helper. |
sandbox.git().pull() |
Fast-forward pull, plus raw result. |
sandbox.git().log(options) |
Parsed commit records with limit, plus raw result. |
sandbox.python(options) / sandbox.javascript(options) |
Open persistent Python or JavaScript code-interpreter kernels. |
sandbox.kernels() |
List active language kernels. |
sandbox.browser() / sandbox.desktop() / sandbox.ssh() |
Open native headless browser, X11 desktop or SSH access. |
sandbox.mounts() |
List active bucket mounts. |
sandbox.keep_alive(duration) |
Extend access and touch activity within project ceilings. |
sandbox.set_ttl(duration) |
Set TTL from now within the project ceiling. |
sandbox.set_idle(duration) |
Set the idle timeout within the project ceiling. |
sandbox.metrics() / sandbox.metrics_since(since) |
Latest node sample, or retained minute series with since. |
sandbox.top(options) |
Stream retained and live node metrics. |
sandbox.wait_until(state, timeout) |
Poll the public state until reached or timed out. |
hb.template(options) |
Build copy/run/ready on a node with from, publish a snapshot version. |
template.rebuild() |
Build a new immutable version from the same local context. |
hb.templates() |
List project template versions. |
hb.webhook(options) |
Register lifecycle delivery and show its secret once. |
hb.webhooks() |
List registrations without secrets. |
webhook.delete() |
Delete this registration. |
webhook.deadletters() |
Inspect exhausted deliveries. |
Handles expose id(), state(), isolation(), units(), preview_url() and files(). Option
and result models are exported at the crate root alongside the handles and HermitboxError. Wire
models come from the committed OpenAPI documents. See
agent security and tiers.
Git works in repo by default, and a clone changes that handle’s path. Tokens go through a
one-call credential helper, never a credential file. A public clone needs permitted internet access
and Git in the image or userland; the wasm tier stages its Git package on demand.
Git clone, push and pull default to five minutes, and other Git operations use the normal command budget. Every method accepts a timeout override. Background maintenance and every Git trace destination stay off during helper calls.
Wasm clones keep metadata in persistent guest storage and checkout files in data, and both survive stop and snapshots.
Shells use serialized pipes with independent stdout and stderr markers. Search and tar budgets and link refusals are in agent security.
Container hostname egress needs the host firewall feature its node advertises. Process sandboxes take it where their node announces kernel network policy (bpf), and wasm refuses it, naming the tier. Webhook signatures and retry limits are in the API reference.
$curl -fsSL https://hbx.sh | shInstall Hermitbox and set it up for me