Skip to content
← all posts

Run a coding agent in a microVM before enabling YOLO mode

YOLO mode gives coding agents a host shell. See how a BoxLite microVM, egress allowlist, and host-side secret proxy keep your host files and keys intact.

Cocona L7 min read

Run a coding agent in a microVM before enabling YOLO mode

Social Post (X / HN)

Running Claude Code without --dangerously-skip-permissions interrupts every step with approval prompts. Turning it on hands a coding agent your host shell. Permission hooks and plain Docker leave gaps because indirect prompt injections can hide inside CLAUDE.md or error logs, and standard containers share your host kernel. BoxLite embeds a microVM runtime as a library using libkrun on macOS Hypervisor.framework or Linux KVM, paired with a host-side OS jailer, an allow_net egress allowlist, and a host-side Secret proxy. No Docker daemon, about a dozen lines of Python. If the agent runs something destructive, you throw away the microVM and keep the rest of your host files and keys intact.


Local coding agents like Claude Code and OpenClaw force a tradeoff. Leave auto-approval off, and every test run or config edit stops for confirmation. Turn on --dangerously-skip-permissions (YOLO mode), and the agent gets a host shell. Work moves faster, and every mistake hits your local machine.

Real incidents go beyond accidental file deletion. As context degrades over a long session, an agent can mishandle path expansion and turn a cleanup command into rm -rf ~/ or wipe an uncommitted Git stash. Indirect prompt injection is harder to spot. When you clone an external repo and ask an agent to debug it, hostile instructions can sit inside CLAUDE.md, AGENTS.md, a README, code comments, error logs, or third-party dependencies.

Security debates around OpenClaw point to the same root cause. When a long-running agent gateway holds read and write access to the host filesystem, reading ~/.ssh, .env, or cloud credentials takes one ordinary command. When a soft sandbox blocks a diagnostic command, agents also show "Escape to Complete" behavior: they look for alternate commands to bypass or disable the restriction so they can finish the task.

Why permission hooks and plain Docker fall short

Many teams start with tool-call hooks like PreToolUse or a permissions.deny denylist. Those checks run in the same user environment as the agent. As long as the agent can run Python, Node, or any compiled binary, it can bypass string-based matching, read .env from a script, and send the contents over the network.

Another common setup puts the agent in a standard Docker container. Containers separate the filesystem view, while sharing one Linux kernel with the host. Untrusted generated code still carries a kernel-escape risk. On macOS, Docker also needs the background Docker Desktop VM, which eats memory and adds licensing costs. Passing real API keys as container environment variables exposes them inside the container. If a prompt injection triggers there, one printenv command can leak every key.

Dual-layer isolation and egress control in BoxLite

BoxLite is an Apache-2.0 open-source embedded microVM runtime. You embed it in your application as a library, with no Docker daemon and no root privileges. It runs standard Open Container Initiative (OCI) images and puts four hard boundaries around coding agents.

Hardware virtualization handles kernel isolation. BoxLite spawns an isolated boxlite-shim child process through ShimController, which calls libkrun to boot a microVM. It uses Hypervisor.framework on Apple Silicon macOS (12 and later) and KVM (/dev/kvm) on Linux and WSL2. Each Box runs its own guest kernel. Even if an agent runs rm -rf / inside the Box, the damage stops at that microVM's disk and never touches the rest of the host filesystem.

A host-side OS jailer backs up the VM layer. If a bug breaks out of the microVM, the jailer limits what host resources boxlite-shim can reach. On Linux, it combines mount, PID, and network namespaces, chroot or pivot_root, Seccomp BPF syscall filtering, dropping to an unprivileged user, and cgroups v2 limits. On macOS, it loads a Seatbelt SBPL profile through /usr/bin/sandbox-exec starting from (deny default), applies rlimits, and separates AF_UNIX control-plane socket permissions from IP network permissions.

An egress allowlist locks down outbound traffic. With NetworkSpec(mode="enabled", allow_net=[...]), BoxLite resolves only allowlisted hostnames and sinkholes every other DNS lookup to 0.0.0.0. To stop an agent from connecting to raw IP addresses to bypass DNS checks, BoxLite inspects TLS SNI and HTTP Host headers on TCP connections. When allow_net contains only hostnames, it also blocks all outbound UDP traffic. For offline tasks, NetworkSpec(mode="disabled") removes the virtual network interface completely.

A host-side secret proxy keeps real credentials out of the guest. When you configure Secret(name, value, hosts), the real key stays on the host. Code inside the guest sees only a placeholder, which defaults to <BOXLITE_SECRET:name> and is also exposed as BOXLITE_SECRET_<NAME>. When the guest sends an HTTPS request to a domain listed in hosts, the host proxy swaps the placeholder for the real secret in the HTTP headers. If a malicious CLAUDE.md tricks the agent into exfiltrating environment variables to an external server, the attacker gets a useless placeholder and the allowlist blocks the request.

flowchart LR
  subgraph L["Bare host or shared-kernel container"]
    direction TB
    A1["Coding Agent (YOLO mode)"] --> A2["Reads real keys from .env and ~/.ssh"]
    A1 --> A3["Host filesystem or shared Linux kernel"]
    A2 --> A4["Exfiltrates credentials via curl to any domain"]
  end

  subgraph R["BoxLite dual-layer isolation and egress filtering"]
    direction TB
    subgraph J["OS Jailer (Linux Seccomp/NS or macOS Seatbelt deny default)"]
      subgraph VM["Hardware MicroVM (libkrun / KVM / Hypervisor.framework)"]
        B1["Coding Agent + isolated guest kernel"]
        B2["Sees only mounted repo and Secret placeholders"]
      end
    end
    B1 --> B3["Host egress gateway (allow_net + Secret proxy)"]
    B3 -->|"Matches allow_net and hosts"| B4["Injects real key and forwards to API host"]
    B3 -->|"Not allowlisted"| B5["DNS sinkhole to 0.0.0.0 and block"]
  end

Put an agent in a microVM with a dozen lines of Python

Install the Python SDK with pip install boxlite (requires Python 3.10 or later). This example uses SimpleBox to mount a local repo read-write so the agent can edit code, restrict outbound traffic to api.anthropic.com, and keep the real API key on the host with Secret:

import os, boxlite

secret = boxlite.Secret(
    name="anthropic", value=os.environ["ANTHROPIC_API_KEY"], hosts=["api.anthropic.com"]
)
net = boxlite.NetworkSpec(mode="enabled", allow_net=["api.anthropic.com"])
async with boxlite.SimpleBox(
    image="python:slim", network=net, secrets=[secret],
    volumes=[("/path/to/repo", "/workspace", False)],
    env=[("ANTHROPIC_API_KEY", "<BOXLITE_SECRET:anthropic>")],
) as box:
    res = await box.exec("sh", "-c", "echo $ANTHROPIC_API_KEY")
    print(res.stdout)  # Prints only the placeholder <BOXLITE_SECRET:anthropic>

To invoke the Claude Code CLI inside an isolated microVM, BoxLite provides SkillBox (see examples/python/06_ai_agents/use_skillbox.py in the repo, and set CLAUDE_CODE_OAUTH_TOKEN first):

import asyncio, boxlite

async def main():
    async with boxlite.SkillBox(skills=["anthropics/skills"]) as box:
        reply = await box.call("Investigate the failing tests in the current directory and propose a fix")
        print(reply)

asyncio.run(main())

For a persistent agent gateway like OpenClaw, examples/python/06_ai_agents/run_openclaw.py shows how to isolate it with SyncBoxlite. It runs ghcr.io/openclaw/openclaw:main, maps only port 18789 and a dedicated config directory, and leaves the host home directory unmounted.

Startup speed and host requirements

Once BoxLite caches the image locally, it boots in seconds, close to docker run. Inside a coding-agent loop where every model response takes several seconds, that startup time barely registers, and you don't have to keep Docker Desktop in memory all day.

The only host requirement is hardware virtualization: Apple Silicon macOS 12 and later, Linux with /dev/kvm, or Windows WSL2 with KVM enabled.

Before turning on auto-approval for a coding agent, isolate the kernel, filesystem, network egress, and credentials in hardware virtualization and a host-side proxy. Don't rely on a prompt reminding the model not to wipe your disk.