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?;- Python Sandbox - Run Python code in a secure sandbox
- Shell Commands - Execute shell commands in the sandbox
- Fully Async - Built with modern async/await support
Check out the examples directory for sample scripts that demonstrate how to:
- Run Python code in a sandbox
- Execute shell commands
- Monitor resource usage
- Configure sandbox options