Skip to main content

A Python client for the Aerol.ai MicroVM sandbox API.

Project description

Aerol.ai MicroVM Python SDK

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

Install

pip install aerolvm-sdk

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,
		},
		"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)

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)

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())

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

aerolvm_sdk-0.2.1.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

aerolvm_sdk-0.2.1-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file aerolvm_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: aerolvm_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aerolvm_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b9bcf9841bdb3dc14574e64d048d6473ecf15212e08e7dab2092c23382696bf2
MD5 81329050bed192189c34ab376e4e73ac
BLAKE2b-256 ab011bdb0b1eca793cdf5eae93b09669820d7c2063d8528eee8357bf76c872eb

See more details on using hashes here.

File details

Details for the file aerolvm_sdk-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: aerolvm_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aerolvm_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ccd4f5a88e2121147e1a71d19bdb2fa825094b29e72827fdc192a695111172a9
MD5 a038a3e6f28214438b2664fe4b1d8d48
BLAKE2b-256 f8784435f9729cbb686fe105f0e01afbe7cbe549edf2c805f1c2d49ec9316494

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