Sandbox.create spawns the VM as a child process. No daemon to install, no server to connect to.
Install the SDK and create your first sandbox
Sandbox.create spawns the VM as a child process. No daemon to install, no server to connect to.
cargo add microsandbox
use microsandbox::{Sandbox, NetworkPolicy};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let sb = Sandbox::builder("my-sandbox")
.image("python:3.12")
.memory(512)
.cpus(2)
.env("PYTHONDONTWRITEBYTECODE", "1")
.workdir("/app")
.volume("/app/src", |v| v.bind("./src").readonly())
.network(|n| n.policy(NetworkPolicy::public_only()))
.create()
.await?;
let output = sb.exec("python", ["-c", "print('Hello, World!')"]).await?;
println!("{}", output.stdout()?);
sb.stop().await?;
Ok(())
}