# MicroVM vs container for agents?

> Source: <https://blog.boxlite.ai/microvm-vs-container-for-agents>
> Published: 2026-12-06 00:14:56.457187+00:00

**Recommendation:** Sandbox untrusted agent code in a microVM with its own guest kernel and a jailed shim process, and set NetworkSpec(mode="disabled") when the sandbox does not need outbound traffic.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

You want an AI agent to write and run untrusted code without putting your host machine or API keys at risk. Standard containers share one Linux kernel with the host, while hardware microVMs give each sandbox its own guest kernel. Pick plain containers for trusted internal services, and use a microVM whenever a model executes untrusted code.

Most teams start with `docker run` because Docker is already on developer laptops and packages dependencies cleanly in OCI images. That setup holds up well for backend services your team wrote and reviewed ahead of time. Once an agent starts generating commands against external repositories at runtime, process isolation and hardware virtualization behave very differently.

A standard Linux container separates filesystem views and process trees using namespaces, `cgroups`, and Seccomp. Every syscall inside that container still goes to the same host Linux kernel shared with your machine and any sibling containers.

A microVM places CPU hardware virtualization (`KVM` on Linux or `Hypervisor.framework` on Apple Silicon macOS) between the workload and the host OS. Each sandbox boots its own guest kernel, keeping untrusted agent syscalls inside that virtual machine boundary.

| Dimension | Standard OCI container | Hardware microVM | 
|---|---|---|
| Kernel boundary | Shared host Linux kernel | Dedicated guest kernel per sandbox | 
| Isolation mechanism | Namespaces, `cgroups` , Seccomp | Hardware virtualization ( `KVM` /`Hypervisor.framework` ) | 
| Escape surface | Shared host kernel syscalls | Hypervisor boundary and virtual devices | 
| Daemon model | Usually requires `dockerd` or a runtime daemon | Daemon-backed or embedded as a library (as in BoxLite) | 
| Packaging format | Standard OCI images | Standard OCI images inside the microVM | 
| Best fit | Trusted services and internal builds | Untrusted LLM code and YOLO coding workflows | 

In [Why do AI agents need a sandbox?](https://blog.boxlite.ai/why-do-ai-agents-need-a-sandbox), we compared bare-host app hooks, standard OCI containers, and microVMs. Bare-host hooks leave an agent running directly alongside your host files. Plain containers separate the filesystem view, yet they leave real exposure when the code isn't trusted.

Kernel-escape bugs are the main technical issue. If model-generated code triggers a Linux kernel bug or slips past a permissive container flag, there's no second kernel boundary stopping it from reaching the host.

On macOS, plain containers add operational drag too. Docker requires a persistent background Linux VM through Docker Desktop, which consumes memory and carries licensing costs for commercial teams. Every container on that Mac still shares that single Linux VM kernel.

You still use standard OCI images when you move a workload into a microVM.

[BoxLite](https://github.com/boxlite-ai/boxlite) is an Apache-2.0 open-source embeddable microVM runtime that you run and manage yourself, with no external daemon and no root privileges. You pull standard OCI images, and BoxLite boots each sandbox (called a Box) inside its own hardware-isolated microVM. It runs on Apple Silicon macOS 12+ via `Hypervisor.framework`, or on Linux and WSL2 via `KVM` (`/dev/kvm`). Once the OCI image is cached locally, a Box boots within seconds, close to `docker run`.

A separate guest kernel doesn't protect secrets you hand straight to the sandbox if outbound traffic stays open. As covered in our [YOLO coding-agent guide](https://blog.boxlite.ai/run-a-coding-agent-in-a-microvm-before-enabling-yolo-mode), BoxLite pairs the microVM with a jailed `boxlite-shim` child process per Box. On Linux, that jailer wraps `boxlite-shim` with `bwrap`, namespaces, `chroot`/` pivot_root`, Seccomp BPF, and `cgroups v2`. On macOS, it applies Seatbelt (`/usr/bin/sandbox-exec` with `(deny default)`) and `rlimits`.

Network rules and credentials stay on the host side too. You can cut off outbound traffic with `NetworkSpec(mode="disabled")`, or use `NetworkSpec(mode="enabled", allow_net=[...])` with a DNS sinkhole to `0.0.0.0` and TLS SNI / HTTP `Host` inspection. Real keys sit behind a `<BOXLITE_SECRET:name>` placeholder on the host, and the host-side `Secret` proxy swaps in the real value only for outbound HTTPS requests matching allowed hosts.

You don't need hardware virtualization for every workload. If you're deploying backend services your own team built and reviewed, standard OCI containers keep overhead low and packing simple.

Plain containers are also practical when your host blocks nested virtualization or doesn't expose `/dev/kvm`. Local hardware-accelerated microVMs can't boot in those environments, so you either rely on the surrounding host VM boundary or send agent execution to a managed remote runtime.

You can deploy BoxLite either on machines you manage or through a hosted service as described in [One SDK, one microVM runtime, from laptop to BoxLite Cloud](https://blog.boxlite.ai/one-sdk-one-microvm-runtime-from-laptop-to-boxlite-cloud).

With the open-source BoxLite runtime, you embed `Boxlite.default()` straight into your host process with no daemon, or run `boxlite serve` on your own servers. You decide whether a Box cleans up immediately after a run or keeps persistent OCI filesystem state with `auto_delete=0`.

When you don't want to manage host virtualization or servers yourself, `Boxlite.rest(...)` connects to BoxLite Cloud, a managed isolated compute environment where AI agents run code, use tools, keep state, and publish apps as services. Start with embedded BoxLite when you own the host machine, and move to BoxLite Cloud when you want BoxLite to run the compute infrastructure.
