Skip to main content
1

Install the SDK

cargo add microsandbox
There are SDKs for many other languages as well. Check the SDK reference for the full list.
2

Install the CLI

The SDK embeds the runtime directly, so no separate server process is needed. Install the msb CLI to manage images, volumes, and sandboxes from the terminal.
curl -fsSL https://get.microsandbox.dev | sh
microsandbox requires Linux with KVM enabled, or macOS with Apple Silicon (M-series chip). Both use hardware virtualization.
3

Run code in a sandbox

Create a sandbox, execute code inside it, and get the result back.
use microsandbox::Sandbox;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let sb = Sandbox::builder("hello")
        .image("python:3.12")
        .memory(512)
        .create()
        .await?;

    let output = sb.exec("python", ["-c", "print('Hello from a microVM!')"]).await?;
    println!("{}", output.stdout()?); // Hello from a microVM!

    sb.stop().await?;
    Ok(())
}

What just happened?

Here’s what actually happened behind that Sandbox.create call:
  1. Pulled the image from Docker Hub (or skipped this if it was already cached, since shared layers are deduplicated).
  2. Assembled the filesystem by stacking the image layers into a copy-on-write filesystem, so nothing you do inside the sandbox modifies the base image.
  3. Booted a microVM as a child process. The 512 MiB you specified is a limit, not a reservation, so the VM only uses what it actually needs.
  4. Started the guest agent inside the VM, which set up the environment and opened a communication channel back to the host.
The exec call sent a message to that guest agent, which spawned python inside the VM, streamed stdout back, and returned the exit code. No SSH involved, no network overhead. The command channel is completely separate from the sandbox’s network stack.
Because exec doesn’t go through the network, it works even when a sandbox has networking disabled via .disable_network() and no network interfaces at all.

Next steps