To quote Solomon Hykes:
An AI agent is an LLM wrecking its environment in a loop.
Your AI agents are one command away from disaster. Here are three critical risks that traditional "YOLO mode" AI deployment exposes you to:
π¨ Destructive Shell Commands - Bad scripts deleting or corrupting critical files, databases, or entire systems
π΅οΈ Data Exfiltration Attacks - Malicious actors stealing source code, secrets, or sensitive data from environment variables
π― Proxy Attacks - Your infrastructure hijacked for DDoS attacks or to mask the origin of cyber attacks against other targets
This open source MicroVM solution eliminates these risks with hardware-level isolation that traditional containers simply cannot provide.
A production-ready AI agent microVM sandbox system using Cloud Hypervisor and Python, providing hardware-level isolation through MicroVMs while maintaining lightweight resource usage. Supports both Linux and Windows guest operating systems.
- Hardware-Level Isolation: KVM-based MicroVMs for strong security boundaries
- Multi-OS Support: Linux (kernel boot) and Windows (UEFI boot) guest VMs
- REST API: FastAPI-based management interface with OpenAPI documentation
- Guest Communication: Bidirectional host-guest communication via HTTP agents
- Snapshot & Restore: Full VM state management for quick provisioning
- Network Management: Automated TAP devices, bridging, and port forwarding
- Resource Management: CPU, memory quotas and system resource monitoring
- Production Ready: Monitoring, scaling, security hardening, and deployment automation
The MicroVM Sandbox includes a lightweight Python SDK for easy integration:
# Install from PyPI
pip install py-microvmQuick Usage:
from microvm_client import MicroVMClient
async with MicroVMClient("http://localhost:8000") as client:
# Create and start a VM
vm = await client.start_vm("my-vm", {"template": "linux-default"})
# Execute commands
result = await client.exec_command(vm.id, "python --version")
print(result.output)
# Upload files
await client.upload_file(vm.id, "script.py", "/tmp/script.py")
# Clean up
await client.destroy_vm(vm.id)Package Information:
- PyPI: https://pypi.org/project/py-microvm/
- Version: 1.0.1
- License: MIT
- Dependencies: httpx, pydantic
βββββββββββββββββββ ββββββββββββββββββββ
β Python SDK β β Management CLI β
βββββββββββ¬ββββββββ ββββββββββ¬ββββββββββ
β REST API β REST API
βββββββββββ¬ββββββββββββββββββββ¬ββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Python REST Server (FastAPI) β
β (Cloud Hypervisor Manager) β
βββββββββββββββββββ¬ββββββββββββββββββββββββ
β HTTP API
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Cloud Hypervisor VMM β
β (Multi-OS Support) β
βββββββββββββββββββ¬ββββββββββββββββββββββββ
β KVM/Hardware
βββββββββββββββββββΌββββββββββββββββββ
β βΌ β
β βββββββββββββββββββ β
β β /dev/kvm β β
β βββββββββββββββββββ β
β β
βββββββ΄ββββββββββββββ βββββββββββββββββββ΄ββββββ
β Linux MicroVM β β Windows MicroVM β
β β β β
β βββββββββββββββββ β β βββββββββββββββββββββ β
β β Guest Servicesβ β β β Guest Services β β
β β & Agent β β β β & Agent β β
β βββββββββββββββββ β β βββββββββββββββββββββ β
β Secure Sandbox β β Secure Sandbox β
βββββββββββββββββββββ βββββββββββββββββββββββββ
- OS: Ubuntu 20.04+ or RHEL 8+
- CPU: 4+ cores with VT-x/AMD-V support
- Memory: 8GB+ RAM (32GB recommended)
- Storage: 50GB+ SSD (200GB NVMe recommended)
- Network: 1Gbps+ interface
- Python >=3.9
- Cloud Hypervisor >=34.0
- KVM (kernel 5.4+)
- Docker (optional, for containerized deployment)
# Clone the repository
git clone https://github.com/CodeDuet/codeduet-microvm-ai-agent-sandbox.git
cd codeduet-microvm-ai-agent-sandbox
# Install system dependencies
sudo ./scripts/setup/install-dependencies.sh
# Install Cloud Hypervisor
sudo ./scripts/setup/install-cloud-hypervisor.sh
# Setup networking
sudo ./scripts/setup/setup-networking.sh
# Install Python dependencies
pip install -r requirements.txt# Copy default configuration
cp config/config.yaml.example config/config.yaml
# Edit configuration as needed
nano config/config.yaml# Development mode
make dev-server
# Or manually
uvicorn src.api.server:app --host 0.0.0.0 --port 8000 --reload# Using the CLI
python -m src.cli vm create --name my-vm --template linux-default
# Using the REST API
curl -X POST http://localhost:8000/api/v1/vms \
-H "Content-Type: application/json" \
-d '{
"name": "my-vm",
"template": "linux-default",
"vcpus": 2,
"memory_mb": 512
}'- Quick Start Guide - Get up and running in minutes
- Installation & Setup - Complete installation instructions
- Your First VM - Create and manage your first VM
- VM Management Guide - Complete VM lifecycle management
- Creating, starting, stopping VMs
- Command execution and file transfer
- Resource allocation and monitoring
- Windows and Linux VM operations
- Troubleshooting Guide - Common issues and solutions
- VM startup problems
- Network connectivity issues
- Performance optimization
- Debug and recovery procedures
- Complete API Documentation - Comprehensive REST API reference
- All endpoints with examples
- Authentication and authorization
- Error codes and responses
- WebSocket endpoints
- Interactive API Docs: Visit
http://localhost:8000/docswhen server is running - Alternative Docs: Visit
http://localhost:8000/redocfor ReDoc interface
- Docker Deployment - Containerized deployment
- Single container setup
- Multi-service docker-compose
- Production configurations
- Monitoring and security
- Kubernetes Deployment - Cloud-native deployment
- Complete manifests and Helm charts
- High availability setup
- Auto-scaling configuration
- Monitoring integration
- Bare Metal Deployment - Direct server installation
- System optimization
- Performance tuning
- Security hardening
- Maintenance procedures
- Creating VMs: See VM Management - Creating VMs
- Managing Snapshots: See VM Management - Snapshot Management
- File Transfer: See VM Management - File Transfer
- Command Execution: See VM Management - Command Execution
- Basic Networking: See VM Management - Network Configuration
- Port Forwarding: See VM Management - Port Forwarding
- Network Isolation: See VM Management - Network Isolation
- Resource Monitoring: See VM Management - Resource Management
- Performance Tuning: See Bare Metal Deployment - Performance Optimization
- Load Testing: See Load Testing Script
- Authentication Setup: See API Reference - Authentication
- Security Hardening: See Bare Metal Deployment - Security Hardening
- Audit Logging: See API Reference - Security Management
- VM Won't Start: See Troubleshooting - VM Creation Failures
- Network Issues: See Troubleshooting - Network Connectivity
- Performance Issues: See Troubleshooting - Performance Issues
- Debug Mode: See Troubleshooting - Advanced Diagnostics
- Integration Tests - VM lifecycle and security integration tests
- Performance Tests - Boot time, resource usage, and load testing
- Load Testing Guide - API load testing framework
- Test Validation - Test syntax and import validation
- High Availability: See Kubernetes Deployment - High Availability
- Auto-scaling: See Kubernetes Deployment - Scaling and Autoscaling
- Monitoring Setup: See Docker Deployment - Monitoring
- Backup & Recovery: See Bare Metal Deployment - Backup and Recovery
# Install development dependencies
pip install -r requirements-dev.txt
# Setup pre-commit hooks
pre-commit install
# Run in development mode
make dev-server# Run core functionality tests (most reliable)
python scripts/testing/run-core-tests.py
# Run all unit tests
pytest tests/unit/ -v
# Run integration tests (requires VM infrastructure)
pytest tests/integration/ -v
# Run performance tests
pytest tests/performance/ -v
# Validate test syntax and imports
python scripts/testing/validate-tests.py
# Run load testing against API
python scripts/testing/load-test.py --users 10 --operations 5
# Run with coverage
pytest --cov=src tests/unit/# Format code
black src/
# Lint code
flake8 src/
# Type checking
mypy src/# Build image
docker build -t microvm-sandbox:latest .
# Run with docker-compose
docker-compose up -d# Deploy to Kubernetes
kubectl apply -f scripts/deployment/kubernetes/# Install as system service
sudo ./scripts/deployment/install-systemd-service.sh
sudo systemctl enable microvm-sandbox
sudo systemctl start microvm-sandboxThe system includes enterprise-grade monitoring and observability:
- Prometheus Metrics: VM performance, resource usage, API metrics
- Grafana Dashboards: Pre-built dashboards for system visualization
- Health Checks: Built-in health endpoints for load balancers
- Structured Logging: JSON logs with correlation IDs
- Performance Testing: Load testing and benchmarking tools
# Access monitoring endpoints
http://localhost:9090 # Prometheus metrics
http://localhost:3000 # Grafana dashboards
http://localhost:8000/health # Health check
http://localhost:8000/status # Detailed status
http://localhost:8000/api/v1/system/metrics # System metrics API
# Performance testing
python scripts/testing/load-test.py --users 50 --operations 10For complete monitoring setup guides, see:
Create custom VM templates in config/vm-templates/:
# config/vm-templates/my-template.yaml
my_template:
vcpus: 4
memory_mb: 2048
kernel: "images/linux/vmlinux.bin"
rootfs: "images/linux/rootfs.ext4"
boot_args: "console=ttyS0 reboot=k panic=1"
guest_agent:
enabled: true
port: 8080# config/networks/custom-network.yaml
networking:
bridge_name: "mybr0"
subnet: "10.0.0.0/24"
port_range:
start: 20000
end: 30000Enterprise-grade security with comprehensive compliance support:
- VM Isolation: Hardware-level isolation via KVM
- Network Security: Separate network namespaces per VM
- Input Validation: Comprehensive request validation and sanitization
- Authentication & RBAC: JWT-based authentication with role-based access control
- Audit Logging: Security events and compliance logging
- Security Scanning: Vulnerability scanning and risk assessment
- Compliance Frameworks: SOC 2, ISO 27001, HIPAA, PCI DSS, GDPR support
Security setup guides:
Target performance metrics:
- VM Boot Time: <3s for Linux, <10s for Windows
- API Response: <100ms for management operations
- Concurrent VMs: 50+ VMs per host
- Resource Overhead: <5% host CPU and memory usage
- Secure Code Execution: Isolate untrusted code execution
- Multi-Tenant Environments: Provide isolated environments for multiple users
- CI/CD Pipelines: Isolate build and test environments
- Security Testing: Safe environment for malware analysis
- Development Environments: Quickly provision development sandboxes
- Cross-Platform Testing: Test applications on multiple OS environments
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Quick Start Guide - Get started in minutes
- Troubleshooting Guide - Common issues and solutions
- Complete API Reference - Full API documentation
- Deployment Guides - Docker, Kubernetes, and bare metal
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Complete Documentation
When reporting issues, please include:
- System Information: OS, hardware specs, Cloud Hypervisor version
- Configuration: Relevant config files (redact sensitive data)
- Logs: Error logs and debug output
- Steps to Reproduce: Clear reproduction steps
- Expected vs Actual: What you expected vs what happened
See our Bug Reporting Guide for detailed instructions.
Built with β€οΈ for secure, lightweight virtualization.