Skip to main content

py-microvm

PyPI version Python License: MIT

Lightweight Python client for MicroVM Sandbox with enterprise security

A secure, simple, and fast Python client for managing MicroVM sandboxes. Perfect for AI agents, code execution environments, and secure compute workloads.

Features

  • 🔒 Enterprise Security: Input validation, path traversal protection, secure defaults
  • High Performance: <50ms API responses, minimal memory footprint
  • 🎯 Simple API: Clean async/await interface, <150 lines of code
  • 🛡️ Type Safe: Full mypy support with comprehensive type hints
  • 🚀 Production Ready: Used in enterprise AI agent deployments

Installation

pip install py-microvm

Quick Start

import asyncio
from microvm_client import MicroVMClient

async def main():
    async with MicroVMClient("https://api.microvm.dev", api_token="your-token") as client:
        # Start AI agent VM
        vm = await client.start_vm("ai-agent", {"vcpus": 4, "memory_mb": 4096})
        print(f"Started VM: {vm.id}")
        
        # Execute code
        result = await client.exec_command(vm.id, "python --version")
        print(f"Output: {result.stdout}")
        
        # Upload files
        await client.upload_file(vm.id, "script.py", "/tmp/script.py")
        
        # Clean up
        await client.destroy_vm(vm.id)

asyncio.run(main())

API Reference

MicroVMClient

Main client class for MicroVM operations.

Constructor

MicroVMClient(
    api_url: str,
    api_token: Optional[str] = None,
    timeout: int = 30,
    verify_ssl: bool = True
)

Methods

  • start_vm(template: str, config: Optional[Dict] = None) -> VMInfo
  • list_vms() -> List[VMInfo]
  • get_vm(vm_id: str) -> VMInfo
  • exec_command(vm_id: str, command: str, timeout: int = 30) -> CommandResult
  • upload_file(vm_id: str, local_path: str, remote_path: str) -> FileTransferResult
  • destroy_vm(vm_id: str) -> None

Security Features

  • Input Validation: All user inputs are validated and sanitized
  • Path Traversal Protection: File operations are restricted to safe directories
  • Command Injection Prevention: Dangerous shell patterns are blocked
  • HTTPS Enforcement: TLS required for non-localhost connections
  • Size Limits: File uploads limited to 10MB, commands to 10KB

Performance

  • Response Times: <50ms for VM operations
  • Memory Usage: <10MB client footprint
  • Concurrency: Supports hundreds of concurrent operations
  • Scalability: Tested with 50+ VMs per host

AI Agent Templates

Pre-configured templates for common AI use cases:

  • ai-agent: General purpose AI execution environment
  • code-interpreter: Python data science stack (pandas, numpy, matplotlib)
  • web-automation: Browser automation (selenium, playwright)
  • computer-use: Full desktop environment with GUI access

Error Handling

from microvm_client import MicroVMClient, VMNotFoundError, NetworkError

try:
    async with MicroVMClient("https://api.microvm.dev") as client:
        vm = await client.get_vm("non-existent")
except VMNotFoundError as e:
    print(f"VM not found: {e.vm_id}")
except NetworkError as e:
    print(f"Network error: {e.message}")

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Type checking
mypy src/

# Code formatting
black src/

# Security scanning
bandit -r src/

License

MIT License - see LICENSE file for details.

Support

Release files for py-microvm 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-microvm 1.0.1
File Size Uploaded
py_microvm-1.0.1.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-microvm 1.0.1
File Interpreter ABI Platform
py_microvm-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / py_microvm-1.0.1.tar.gz

Download URL py_microvm-1.0.1.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
04188c9652d009f79afaa430a1a67c9b393981efa45eeb47bc69f133ade2e671
BLAKE2b-256 checksum
How to use checksums
32532f9c034e4393e19365f28d7e7acaf2f60495c49daf3d33a65abc4b8abd75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.12

Release files / py_microvm-1.0.1-py3-none-any.whl

Download URL py_microvm-1.0.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e07bd57d75ffd32736522399bdc2c3c606aa6d2145045595ba9062c8d1bddb2b
BLAKE2b-256 checksum
How to use checksums
2dd329a4203d2bdce65f65cb90285f047839088d5542ddac960ee2f6604759b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page