Skip to content

CapsaCross-Platform Virtual Machines for Rust

A batteries-included Rust library for running lightweight VMs with a focus on security, simplicity, and embeddability.

Quick Example

rust
use capsa::{Capsa, LinuxDirectBootConfig};
use std::time::Duration;

#[tokio::main]
async fn main() -> capsa::Result<()> {
    // Create and start a VM
    let vm = Capsa::vm(LinuxDirectBootConfig::new("kernel", "initrd"))
        .cpus(2)
        .memory_mb(512)
        .console_enabled()
        .build()
        .await?;

    // Interact via console
    let console = vm.console().await?;
    console.wait_for_timeout("# ", Duration::from_secs(30)).await?;

    let output = console.exec("uname -a", Duration::from_secs(5)).await?;
    println!("Kernel: {}", output);

    // Clean shutdown
    vm.stop().await?;
    Ok(())
}

Use Cases

AI Coding Agents

Run untrusted code in isolated VMs with fine-grained network policies. Allow only specific API endpoints while blocking everything else.

rust
let policy = NetworkPolicy::deny_all()
    .allow_domain("api.anthropic.com")
    .allow_domain("*.github.com");

let vm = Capsa::sandbox()
    .network(NetworkMode::user_nat().policy(policy).build())
    .run("/bin/agent", &[])
    .build().await?;

Integration Testing

Pre-warm VM pools for fast test execution. Each test gets a fresh VM without boot overhead.

rust
let pool = Capsa::pool(config)
    .console_enabled()
    .build(4)  // 4 pre-warmed VMs
    .await?;

// In tests
let vm = pool.reserve().await?;
// Run test...
drop(vm); // VM automatically replaced

Sandboxed Environments

Share specific directories with guests while maintaining isolation. Perfect for build environments and code execution.

rust
// Linux only - shared directories require virtio-fs
let vm = Capsa::sandbox()
    .share("./workspace", "/mnt/code", MountMode::ReadWrite)
    .run("/bin/sh", &["-c", "make -C /mnt/code"])
    .build().await?;

Platform Support

FeatureLinux (KVM)macOS
Linux Direct BootSupportedSupported
UEFI Boot-Supported
virtio-fs SharesSupportedComing Soon
NetworkingSupportedSupported
VM Sockets (vsock)SupportedSupported
VM PoolsSupportedSupported
Sandbox ModeSupportedSupported

Next Steps

Released under the MIT License.