Skip to main content

Aerol.ai MicroVM Python SDK

A lightweight Python SDK for the Aerol.ai MicroVM sandbox API.

Install

pip install aerolvm-sdk

For the asyncio client, AsyncMicroVM, add the async extra. It pulls in httpx; the plain install needs only websocket-client:

pip install "aerolvm-sdk[async]"

For local development from this repository:

cd sdk/python
pip install .

Usage

from microvm import MicroVM

client = MicroVM(pat_token="${SB_PAT_TOKEN}", api_url="https://sandbox.example.com")
health = client.health()
print(health)
print(health["sshGateway"])

sandbox = client.create(
	{
		"image": "ghcr.io/aerol-ai/ubuntu:22.04",
		"lifecycle": {
			"stopIfIdleFor": 3_600_000_000_000,
			"destroyAtAge": 86_400_000_000_000,
		},
		"failover": {"policy": "recreate"},
		"mounts": [
			{
				"type": "s3",
				"target": "/workspace",
				"source": "s3://bucket/prefix",
				"credentials": {"access_key_id": "AKIA...", "secret_access_key": "SECRET"},
			}
		],
	}
)
print(sandbox.sshPublicKey)
print(sandbox.sshPrivateKey)  # only returned by create()
print(client.mounts(sandbox.id))

sandbox.update_lifecycle(
	{
		"stopIfIdleFor": 7_200_000_000_000,
		"destroyAtAge": 172_800_000_000_000,
	}
)
print(sandbox.lifecycle)

Async client

AsyncMicroVM has every call MicroVM has, as coroutines, built from the same request code. Use it with async with so its connection pool is closed. Stream callbacks (onStdout, file watch events) run on the event loop.

import asyncio

from microvm import AsyncMicroVM


async def main() -> None:
    async with AsyncMicroVM() as client:
        sandboxes = await asyncio.gather(
            *(client.create(image="python:3.12", destroy_on_exit=True) for _ in range(3))
        )
        for sandbox in sandboxes:
            async with sandbox:
                result = await sandbox.exec("python -c 'print(42)'", timeout=60)
                print(result["stdout"])


asyncio.run(main())

Build Images

from microvm import Image, MicroVM

client = MicroVM(pat_token="${SB_PAT_TOKEN}", api_url="https://sandbox.example.com")
image = Image.base("ubuntu:22.04").run_commands("apt-get update", "apt-get install -y curl")

# create() accepts an Image directly
sandbox = client.create({"image": image})

# or build it explicitly and reuse the content-addressed tag
tag = client.build_image(image)
print(tag)

Example

python examples/create_sandbox.py --api-url http://127.0.0.1:21212 --pat-token test --image ghcr.io/aerol-ai/ubuntu:22.04

Streaming exec

import sys

handle = sandbox.exec_stream(
	{
		"command": "bash",
		"tty": True,
		"cols": 120,
		"rows": 40,
		"onStdout": lambda chunk: sys.stdout.buffer.write(chunk),
	}
)

handle.write("echo hello\n")
result = handle.wait()
print(result)

Watching files

Works on gVisor and Firecracker sandboxes. Other runtimes answer with a MicroVMHTTPError whose status_code is 501.

handle = sandbox.watch_files(
	"/workspace",
	lambda event: print(event.type, event.path),
	recursive=True,
)
sandbox.exec("touch /workspace/new.txt")
handle.stop()

An event with type overflow means some changes were lost. List the folder again to catch up.

Sessions

import sys

session = sandbox.create_session(
	{
		"name": "shell",
		"command": "bash",
		"workDir": "/workspace",
		"pty": True,
		"cols": 120,
		"rows": 40,
	}
)

print(session)
print(sandbox.list_sessions())
print(sandbox.session_log(session["id"]).decode("utf-8"))

handle = sandbox.attach_session(
	session["id"],
	{
		"cols": 120,
		"rows": 40,
		"onStdout": lambda chunk: sys.stdout.buffer.write(chunk),
	}
)
handle.write("echo attached\n")
print(handle.wait())

Metadata

Release files for aerolvm-sdk 0.8.2

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

Source distribution (sdist)

Source distribution for aerolvm-sdk 0.8.2
File Size Uploaded Provenance Actions
aerolvm_sdk-0.8.2.tar.gz 127.6 kB Without provenance Details for aerolvm_sdk-0.8.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aerolvm-sdk 0.8.2
File Interpreter ABI Platform Actions
aerolvm_sdk-0.8.2-py3-none-any.whl Python 3 none any Details for aerolvm_sdk-0.8.2-py3-none-any.whl

Total release size: 206.4 kB

Release files / aerolvm_sdk-0.8.2.tar.gz

Download URL aerolvm_sdk-0.8.2.tar.gz
Size 127.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2e50c8fd9c23c77c528bcc869d7725be024ba6fc0678d3223fb2b3e8c5fb05fa
BLAKE2b-256 checksum
How to use checksums
55649a929d6927e38bdcc8c6fcc9665495c4bf82a8cf1d7c0c4a91c9a42cf70d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / aerolvm_sdk-0.8.2-py3-none-any.whl

Download URL aerolvm_sdk-0.8.2-py3-none-any.whl
Size 78.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b58735b597adfdb6f8e8de3191656b062878caebaf304b180734235b3d1ebcd
BLAKE2b-256 checksum
How to use checksums
14e0f5887d8d5980957acc898b0257b60950833a39ed5d8d4e9b453048a48f67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for aerolvm-sdk 0.8.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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