docs/sdk/overview.mdx
The SDK embeds the microsandbox runtime directly into your application. Creating a sandbox spawns a local VM as a child process; there is no daemon to install and no server to connect to.
npm install microsandbox
pip install microsandbox
go get github.com/superradcompany/microsandbox/sdk/go
Create a sandbox from a container image, run a command, print the output, and stop it.
<CodeGroup> ```rust Rust use microsandbox::Sandbox;#[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let sb = Sandbox::builder("hello") .image("python") .create() .await?;
let output = sb.exec("python", ["-c", "print('Hello, World!')"]).await?;
println!("{}", output.stdout()?);
sb.stop().await?;
Ok(())
}
```typescript TypeScript
import { Sandbox } from "microsandbox";
await using sb = await Sandbox.builder("hello")
.image("python")
.create();
const output = await sb.exec("python", ["-c", "print('Hello, World!')"]);
console.log("Output:", output.stdout());
import asyncio
from microsandbox import Sandbox
async def main():
sb = await Sandbox.create(
"hello",
image="python",
)
output = await sb.exec("python", ["-c", "print('Hello, World!')"])
print("Output:", output.stdout_text)
await sb.stop()
asyncio.run(main())
package main
import (
"context"
"fmt"
"log"
m "github.com/superradcompany/microsandbox/sdk/go"
)
func main() {
ctx := context.Background()
sb, err := m.CreateSandbox(ctx, "hello", m.WithImage("python"))
if err != nil {
log.Fatal(err)
}
defer func() {
_, _ = sb.StopAndWait(context.Background())
_ = sb.Close()
}()
out, err := sb.Exec(ctx, "python", []string{"-c", "print('Hello, World!')"})
if err != nil {
log.Fatal(err)
}
fmt.Println("Output:", out.Stdout())
}
Choose the SDK for your language:
For low-level protocol integrations, see the Agent Client references for Rust, TypeScript, Python, and Go. See also error handling.