microvms-core
Run agents, shell commands, builds, and tests inside AWS Lambda MicroVMs from Rust.
Your application controls a remote sandbox through Sandbox and Session: launch
a VM, copy a workspace, execute tools, collect results, and terminate it. The
agents module also provisions Claude Code or Codex with Amazon Bedrock access.
Run your first command
You need Rust, AWS credentials with MicroVM access, a VM execution role, and an
image containing agentd. Complete the one-time AWS setup
if this is your first use. AWS usage is billed; a first image build takes several
minutes. Once an image exists, the example below is the full launch-to-cleanup path.
Use the CLI to prepare a reusable image, then copy data.imageIdentifier from
its JSON output:
The image and this example use us-east-1. Set MICROVM_IMAGE to the actual ARN;
the SDK can also resolve an image name in that region. Set
MICROVM_EXECUTION_ROLE_ARN to the actual execution role ARN from setup.
AWS credentials come from
the standard credential chain, including AWS_PROFILE and environment variables.
Replace the empty [dependencies] section in Cargo.toml with:
[]
= "1.0"
= { = "1", = ["macros", "rt-multi-thread"] }
Replace src/main.rs with:
use Duration;
use *;
use ;
use ;
use mint_exec_id;
async
Expected output includes hello from a sandbox and exit: Some(0).
use microvms_core::prelude::*; brings the constructors that wire in AWS, such as
Sandbox::new, into scope.
A request with no with_cwd uses the image's working directory. Set a different
directory only after creating it or uploading files there; a generic image need not
contain /workspace.
Cleanup requests VM termination and retains the image for reuse. Dropping a
Sandbox does not terminate it; always call terminate and inspect its report.
Use TeardownOpts::default().waiting_for_terminated() when you must wait for
AWS to report termination complete.
Give an agent its own sandbox
Use a separate VM for each task or workspace, upload only the files it needs,
run tools through the session, and download the results before cleanup.
Session::upload_file, upload_tar, download_file, and download_tar handle
transfers; Session::run returns an ExecHandle for streaming and cancellation.
For built-in coding agents, start with
running Claude Code or Codex.
Rust's agents::AgentVm composes image preparation, launch, Bedrock credential
installation, and prompts. Agent prompts run as uid/gid 1000. The generic command
example above runs as the image's AGENTD_DEFAULT_USER when the image sets one,
and as the daemon's user, normally root, when it doesn't.
The VM separates workload execution from your host. Processes within one guest share that VM; uid demotion is not a separate security boundary. Guest workloads can access the VM execution role through metadata, so scope that role accordingly. Agent helpers request internet access. Omitting egress does not block the default network, and proxy-deny variables are advisory. Enforced internet isolation needs a VPC connector and verified VPC routing without internet access. See trust boundaries and networking.
Next steps
- API documentation: lifecycle, sessions, agents, sizing, and costs.
- Use the SDKs: Rust, Python, and Node examples.
- Custom guest images: install your own agent and tools.
- Embedding guide: longer-running applications and harnesses.
Apache-2.0