| Crates.io | microsandbox |
| lib.rs | microsandbox |
| version | 0.1.2 |
| created_at | 2025-04-02 18:49:33.247313+00 |
| updated_at | 2025-05-22 13:07:38.402071+00 |
| description | Rust SDK for microsandbox - secure self-hosted sandboxes for your AI agents |
| homepage | https://microsandbox.dev |
| repository | https://github.com/microsandbox/microsandbox |
| max_upload_size | |
| id | 1616926 |
| size | 112,464 |
A Rust SDK for microsandbox - secure self-hosted sandboxes for executing untrusted code. This SDK allows you to create isolated environments for running code with controlled access to system resources.
Add this to your Cargo.toml:
[dependencies]
microsandbox = "0.1.0"
tokio = { version = "1", features = ["full"] }
use microsandbox::{SandboxOptions, PythonSandbox};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a Python sandbox
let mut sb = PythonSandbox::create(SandboxOptions::builder().name("test").build()).await?;
// Run Python code
let exec = sb.run(r#"name = "Python""#).await?;
let exec = sb.run(r#"print(f"Hello {name}!")"#).await?;
// Get the output
println!("{}", exec.output().await?); // prints Hello Python!
// Stop the sandbox
sb.stop().await?;
Ok(())
}
The SDK will automatically read environment variables:
MSB_API_KEY - Your API key for authenticationMSB_SERVER_URL - The URL of the microsandbox server (defaults to http://127.0.0.1:5555)You can also set these values programmatically:
let sb = PythonSandbox::create(
SandboxOptions::builder()
.name("test")
.api_key("msb_your_api_key")
.server_url("http://your-server-url:5555")
.build()
).await?;
Check out the examples directory for sample scripts that demonstrate how to: