Tutorials
VMs vs Containers vs MicroVMs: Which to Choose for Your Workloads
Flavius Dinu8 min read
TL;DR:
- Virtual Machines (VMs) are slow to boot and consume the most resources, but provide the strongest isolation through hardware virtualization.
- By sharing the host kernel, containers are extremely fast and portable, but at the same time the isolation boundary is soft.
- MicroVMs (Firecracker, Kata Containers) strip the VM down to its essentials, booting in seconds with a hardware-level boundary.
- For untrusted code and autonomous AI agents, MicroVMs are quickly becoming the required standard, especially under regulations like the EU AI Act.
Infrastructure has gone through three big shifts in the last two decades. First, we ran applications directly on physical servers. Then Virtual Machines (VMs) let us slice one server into many isolated systems. Then containers made everything faster and lighter. Each step traded something away to gain something else, and the trade has almost always been the same: strong security isolation on one side, speed and agility on the other.
VMs give you a hardened boundary but they're heavy. Containers are fast but they share the host kernel. For years, you had to pick one of the two.
MicroVMs are the technology that finally refuses to pick. They give you container-like startup speed inside a real, hardware-enforced VM boundary.
In this article, we'll walk through how all three work, where each one still wins, and why MicroVMs are becoming the default answer for untrusted code and AI agent workloads.
Check out the video:
What is a Virtual Machine?
A virtual machine is a complete computer that runs directly in software, having its own guest operating system, its own kernel, and even its own virtual hardware.
What makes this virtualization possible is the hypervisor, and this comes in two flavors:
- Bare-metal: This runs directly on the physical hardware (KVM, VMware ESXi, Xen, and others). These are typically used in cloud providers and data centers.
- Hosted: These run as an application on top of an existing OS (VirtualBox and VMware being classic examples). They are great for personal computers, not for production use cases.
The hypervisor helps you divide the physical machine's CPU, memory, storage, and network into isolated slices, so each guest OS believes that it has all the hardware to itself.
The big strength of a VM is hardware isolation, and a VM can't see or interact with another VM's memory because the boundary is enforced by the CPU itself. This still makes VMs the gold standard for multi-tenant environments where you're running workloads from different customers or even teams that shouldn't interact with each other, everything on the same hardware.
The biggest weakness of a VM is its weight, and this happens because every VM boots a full operating system, meaning that boot times are measured in minutes, and the memory footprint is measured in gigabytes, even before your application starts. If you are running, for example, 100 VMs, this means that you are running 100 kernels, and 100 copies of everything an OS needs.
What is a Container?
Containers have a different approach from virtual machines. They are not virtualizing the hardware as VMs do, they are virtualizing the operating system. This means that every container on a single host shares the same kernel.
There are two Linux kernel features that keep them separated:
- Namespaces: They control what a container can actually see (its own process tree, network interfaces, filesystem view, and hostname).
- cgroups: They control what a container can actually use (CPU, memory, and I/O limits).
Containers boot in milliseconds and add almost no overhead because there is no guest OS to boot. With a container image you can bundle your application with its dependencies, and then this same image will run exactly the same on your laptop, on your colleague's laptop, in the cloud, or in CI/CD pipelines. They solve the "it works on my machine" problem.
Kubernetes (K8s) transformed container orchestration. With K8s you can schedule, scale, and self-heal your containers, making it easy to run and manage thousands of them.
Because containers have a shared kernel, an attacker that finds a kernel vulnerability and escapes the container will land on the host. By landing on the host, they will get a path to every other container running on that host.
This doesn't make containers insecure. If you trust the code you are running (your own microservices, your own CI/CD pipelines), the shared kernel and its risks are a reasonable tradeoff for the speed you get. The problem with containers comes when you run something that you can't fully trust.
What is a MicroVM?
So a VM is a strong but heavy option, while a container is a fast but soft option.
A MicroVM is the middle option, and it's a real virtual machine that runs on a stripped-down hypervisor with a minimal guest kernel and almost no emulated devices. There are two implementations that are well known:
- Firecracker: This is built by AWS to power Lambda and Fargate. It emulates only a handful of devices, and boots a guest in around 125 milliseconds with roughly 5 MB of memory overhead per MicroVM.
- Kata Containers: This wraps each container (or pod) in its own lightweight VM, so you can keep your K8s workflows while gaining a hardware boundary.
A virtual machine emulates all the hardware, but almost none of it is needed to run modern Linux workloads. MicroVMs delete all of it, and what's left boots in seconds (often less), and exposes only a tiny surface to attacks.
With a MicroVM you get the security profile of a VM, with the density and deployment speed of a container.
And this matters beyond performance, because regulations like the EU AI Act and the Cyber Resilience Act are pushing hard requirements around how software (especially AI systems) must be contained and controlled. MicroVMs make it practical to give every workload an immutable and isolated environment with a clean and auditable boundary.
MicroVM adoption is rising right now, and this happens because of autonomous AI agents. AI agents are not normal applications, because they generate and execute actions at runtime, meaning that you can't fully review their behavior in advance. This makes them non-deterministic.
If an agent runs in a plain container and something goes wrong, and many things can (prompt injection, a compromised tool, or even a hallucinated command), the shared kernel is a thin wall between one misbehaving agent and your entire host.
Agents need bounded execution where each of their actions is observable, and the blast radius of a mistake is one disposable MicroVM, not a cluster-wide incident. This is exactly why MicroVMs are becoming a baseline requirement for agentic infrastructure.
When to choose Virtual Machines, Containers, or MicroVMs?
Each of these three have their own strengths and weaknesses, and they all have a path where they are the clear winner:
- VMs should be chosen for complex and stateful applications that need high-performance hardware.
- Containers are the right choice where iteration speed is a primary driver (your own microservices, CI/CD pipelines, and standard cloud native environments).
- MicroVMs should be chosen for Function as a Service platforms, untrusted code execution, and AI agent sandboxing.
How does Lens Agents use MicroVM Isolation?
Lens Agents is a governed platform for running AI agents against real enterprise systems. In the platform, every agent runs in its own isolated execution environment, so a misbehaving or compromised agent is contained by design.
The agents running in the platform don't have access to the real credentials they need to use, as they are injected at the network boundary. They always hold just placeholder credentials, so even if an agent is compromised, the attacker will get away with nothing.
At the same time, every action an agent takes is logged and fully auditable, which maps directly to the traceability requirements in the EU AI Act.
See Lens Agents in action:
Key points
Infrastructure isn't a choice between just Virtual Machines and Containers anymore. Modern platforms will run three: VMs for heavy workloads, containers for trusted cloud-native services, and MicroVMs for everything that needs container-like speed and requires a more powerful boundary.
If you want to see how governed and isolated AI agents work in practice, book a demo with the Lens team.
FAQ
Are MicroVMs replacing containers?
No, MicroVMs and containers solve different problems. For trusted cloud native microservices, containers remain the better choice because nothing beats their density and startup speed. MicroVMs take over in cases where code cannot be fully trusted: multi-tenant platforms, serverless functions, and AI agent execution.
Can I run MicroVMs on my existing Kubernetes cluster?
Yes, and the most common path is Kata Containers. The main requirement is that your Kubernetes nodes support hardware virtualization (or nested virtualization if your nodes are VMs themselves).
Why can't I just sandbox AI agents with regular container security tools?
AI agents are a special case because they are generating actions at runtime. This means that you can't review their behavior in advance the way you review your own code. By having a hardware-enforced boundary, even if an agent is compromised, the damage stops at the edge of one disposable MicroVM.