Skip to main content

Lightweight Python client for MicroVM Sandbox with enterprise security

Project description

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

Related Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_microvm-1.0.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_microvm-1.0.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file py_microvm-1.0.0.tar.gz.

File metadata

  • Download URL: py_microvm-1.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for py_microvm-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1680b61093a6c149697dfeceac80a757801199dc143c7686ed296cd4b041a05f
MD5 8d808b6f11507716627074aa06922505
BLAKE2b-256 577613c66723f66be782d30e71f0e6259ef762a7eea82566c2d8366d462d2a98

See more details on using hashes here.

File details

Details for the file py_microvm-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: py_microvm-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for py_microvm-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ba52092597e0f7917e3316aecb514ae5da72a9264fd32f7bb73c44d8e2b0e0f
MD5 4db63cd005b2d15bedf3baa92762978a
BLAKE2b-256 9f88ef720cec88d26a8480e7089f6b24155d1dc1a7cbded4fb2b1a8944ab9352

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page