docs/sdk/overview.mdx
The SDK embeds the microsandbox runtime directly into your application. Running locally, creating a sandbox spawns a VM as a child process; there is no daemon to install and no server to connect to. With an API key set, the same SDK runs sandboxes on microsandbox cloud instead.
npm install microsandbox
pip install microsandbox
go get github.com/superradcompany/microsandbox/sdk/go
For explicit runtime installation, verification, custom install locations, and environment overrides, see Runtime setup.
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()
if err := m.EnsureInstalled(ctx); err != nil {
log.Fatal(err)
}
sb, err := m.CreateSandbox(ctx, "hello", m.WithImage("python"))
if err != nil {
log.Fatal(err)
}
defer func() {
_ = sb.Stop(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.