Skip to main content

microvms

Run coding agents and their tools in sandboxed AWS Lambda MicroVMs. Give each task its own Linux workspace, execute commands, collect files, and terminate the VM from Python. AgentVm runs Claude Code or Codex through Amazon Bedrock; Sandbox supports your own agent or command runner.

Install

python3 -m venv .venv
. .venv/bin/activate
python -m pip install microvms

Requires CPython 3.9+. On Windows, activate with .venv\Scripts\Activate.ps1 in PowerShell. Wheels ship for Linux x64/ARM64 (glibc), macOS Intel/Apple Silicon, and Windows x64. Type declarations are included.

Run your first command

With an existing image and AWS credentials, this is the 90-second path to a working SDK example. One-time AWS setup and image builds take longer.

You need Lambda MicroVMs access, your normal AWS credential configuration, and an execution role. Follow AWS setup to set AWS_REGION and MICROVM_EXECUTION_ROLE_ARN. Then use the CLI to prepare an image containing agentd:

microvm build --name agent-tools --json
export MICROVM_IMAGE='paste data.imageIdentifier from the result'

Use the image ARN, in the same account and region as your credentials. The CLI can resolve image names; the SDK example takes the ARN directly. The CLI provisions agentd and uploads the build artifact for you. Shell examples use Bash or Zsh; in PowerShell, set variables with $env:NAME='value'.

Save as hello.py:

import os
import sys
from microvms import Region, Sandbox

image = os.environ["MICROVM_IMAGE"]
role = os.environ["MICROVM_EXECUTION_ROLE_ARN"]
vm = Sandbox(Region.parse(os.environ.get("AWS_REGION", "us-east-1")))
try:
    session = vm.run(image_identifier=image, execution_role_arn=role)
    result = session.run_sync(["echo", "hello from a sandbox"])
    print(result.stdout, end="")
    print(result.stderr, end="", file=sys.stderr)
    if not result.ok:
        raise RuntimeError(f"Command exited with {result.exit_code}")
finally:
    cleanup = vm.terminate()
    if cleanup.failures or cleanup.undeleted:
        print("Cleanup needs attention:", cleanup.to_dict(), file=sys.stderr)
python hello.py

Expected output: hello from a sandbox. The VM is terminated after the command; the image stays available for reuse. terminate() returns once termination is accepted by default. Pass wait_for_terminated=True to wait for the final state. Inspect failures and undeleted because cleanup reports failures in its result.

Run a coding agent

First prepare a Claude Code image using the same AWS setup plus Bedrock permissions. This builds or reuses the agent image and starts a temporary VM. Capture only its image ARN, then terminate that temporary VM:

MICROVM_AGENT_IMAGE="$(microvm agent-up --vm-name sdk-image --agent claude-code --json |
  python -c 'import json, sys; print(json.load(sys.stdin)["data"]["imageIdentifier"])')"
export MICROVM_AGENT_IMAGE
microvm terminate sdk-image --wait

Save as agent.py. The agent writes a file inside its own VM; the SDK downloads that file before cleanup:

import os
import sys
from microvms import AgentVm, Region

image = os.environ["MICROVM_AGENT_IMAGE"]
role = os.environ["MICROVM_EXECUTION_ROLE_ARN"]
vm = AgentVm(Region.parse(os.environ.get("AWS_REGION", "us-east-1")))
try:
    session = vm.launch(image_identifier=image, execution_role_arn=role)
    vm.install_access()
    result = vm.prompt_sync(
        "claude-code",
        "Create /workspace/hello.py that prints hello from a sandbox. Run it.",
    )
    print(result.stdout, end="")
    print(result.stderr, end="", file=sys.stderr)
    if not result.ok:
        raise RuntimeError(f"Agent exited with {result.exit_code}")
    with open("hello-from-agent.py", "wb") as artifact:
        artifact.write(session.download_file("/workspace/hello.py"))
finally:
    cleanup = vm.terminate()
    if cleanup.failures or cleanup.undeleted:
        print("Cleanup needs attention:", cleanup.to_dict(), file=sys.stderr)
python agent.py

For Codex, prepare the image with --agent codex, import AgentSpec, create AgentVm(region, [AgentSpec.codex()]), and prompt "codex". Agent images must contain the agent you select. Agents run as UID/GID 1000 in /workspace; install_access() installs a short-lived Bedrock token after launch. AgentVm enables internet egress for model calls.

Next steps

For a Sandbox named vm and its session:

Need API
Start a task and poll or stream later session.run(argv) → ExecHandle
Wait for and release saved output handle.wait_and_ack(timeout=60)
Keep the VM awake while an exec runs with session.keep_awake(while_busy=True): ...
Upload input or download results session.upload_file(path, bytes), session.download_file(path)
Transfer a directory session.upload_tar(path, tar_bytes), session.download_tar(path)
Freeze and restore a workspace vm.suspend(), vm.resume()

Methods are synchronous. run_sync starts a command, waits, and acknowledges its saved output. A nonzero exit is a result, so check result.ok or result.exit_code. Use shell=True when passing a shell script string. Library exceptions expose code, kind, wire_kind, and retryable.

Omitting egress does not block outbound traffic. For no egress, use egress_network_connectors=[vpc_connector_arn] with a VPC without an internet gateway, NAT gateway, or other internet route. deny_egress sets advisory proxy variables that workloads can bypass. Keep the guest execution role limited to the task's needs.

SDK tutorial · API reference · Source · Apache-2.0

Release files for microvms 0.10.0

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

Source distribution (sdist)

Source distribution for microvms 0.10.0
File Size Uploaded
microvms-0.10.0.tar.gz 868.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for microvms 0.10.0
File
microvms-0.10.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
microvms-0.10.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
microvms-0.10.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
microvms-0.10.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
microvms-0.10.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 17.5 MB

Release files / microvms-0.10.0.tar.gz

Download URL microvms-0.10.0.tar.gz
Size 868.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b1fa5654a217507d05c899de07a1bfa12efb086701575f3bdcaa9b4f0822a669
BLAKE2b-256 checksum
How to use checksums
b03b4432815c390f36bd2ffcf380a71b0d851b533f893c6d214456f30c28842c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / microvms-0.10.0-cp39-abi3-win_amd64.whl

Download URL microvms-0.10.0-cp39-abi3-win_amd64.whl
Size 3.4 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1c1f4b62437e94d1912b32177e8e8234e95ecab3dc4c36723e9a14c8c7ee970b
BLAKE2b-256 checksum
How to use checksums
f4d5cb1ffc645a2bcac2ddb89679247cb8d6cb2f6640b0b57622c94ee64467bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / microvms-0.10.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL microvms-0.10.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.5 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
1fec9d17a5a6ebd705d41669340b25035d91ba55e81d067e9e5fdc650b5177dc
BLAKE2b-256 checksum
How to use checksums
b27f3efafb3c5532a8e414656a4d4ffb41cfe7e18c1b140dcbb37ea3bf4435fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / microvms-0.10.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL microvms-0.10.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.4 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2c590d8f0999cc2b2511be03d31b99e498e2cdff50f59409843b2e5e7b63f28a
BLAKE2b-256 checksum
How to use checksums
f319eca735e4887185e9195e1cd7f679eeced0d224850d0c0683e2df4caa2e17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / microvms-0.10.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL microvms-0.10.0-cp39-abi3-macosx_11_0_arm64.whl
Size 3.1 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7092f9c2d9d422b9bae16072c0ac1b10910a53da223adc257b5b796adbb2dcdc
BLAKE2b-256 checksum
How to use checksums
69ebfb1858a4dc62cfcc137a33c71741e29154294c8f414816a836f12a989344
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / microvms-0.10.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL microvms-0.10.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 3.3 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a738baa3f6f57ed1939f30f97156828fe5b45a3762e4136034ab3958bee1b4ae
BLAKE2b-256 checksum
How to use checksums
e58bbb99a9d503384eff972c14079f92e8574a938f065398dd31b586d52efd4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.10.0 This release

6 release files

0.9.0

6 release files

0.8.0

6 release files

0.7.0

6 release files

0.6.0

6 release files

0.5.0

6 release files

0.4.0

6 release files

0.3.0

6 release files

0.2.0

6 release files

0.1.1

6 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