Three concentric black rings form a bunker on the left; a small amber figure inside represents an AI agent. A red arrow points from the centre out to a dashed cream firewall ring, then crossed out by a red X to mark zero outbound traffic. A cream 'reset' arrow loops back to the bunker to suggest ephemerality. Bauhaus punctuation dots.
[ Networking & Security ]7 min read

The Triple Gap Protocol: Keeping AI Contained

Phase 4 · Autonomous Agents and UX

A containment architecture for autonomous agents that can write and execute their own code, and why ephemeral is the safety property that matters.

Proxmox VEQEMUnftablescloud-init

There is a moment in the life of a homelab where you stop using AI and start letting AI do things. The difference is small in the grammar and enormous in the consequences. Letting a model write code is prompt plus response; letting it execute code is prompt plus response plus an arbitrary set of system calls. The former has never corrupted a filesystem. The latter can, will, and eventually did.

I did not build the containment architecture because I thought an agent was malicious. I built it because I thought an agent was confidently wrong. The failure mode I worry about is not “the model plots against me”; it is “the model generates a shell command that looks reasonable and happens to be destructive because the task prompt was ambiguous”. A hazmat suit inside a locked room inside a bunker is the same architecture you would build if the threat were malice or incompetence. The cost is identical. The benefit covers both cases.

The Analogy

Bio-safety Level 4 laboratories do not assume the pathogen is clever. They assume the pathogen is there, and that any accidental breach should stop at the nearest containment layer. The design is defensive in depth: a primary barrier (the cabinet), a secondary barrier (the sealed room), and a tertiary barrier (the building’s negative-pressure corridor). A failure of the cabinet is contained by the room. A failure of the room is contained by the corridor. You do not get to “everyone outside the building is exposed” unless three independent systems fail at once.

Autonomous agents need the same shape. A single firewall rule is not enough. A single VM is not enough. Three independent layers, each of which would be adequate on its own, buy you the property that a single mistake does not cascade.

The Tech Translated

The “Triple Gap” in my lab:

  1. Gap 1: the ephemeral VM. Every agent task starts by cloning a fresh Ubuntu cloud image from a golden template. The clone is the agent’s workspace for the duration of one task and is destroyed when the task finishes or after a 30-minute timeout, whichever comes first. A corrupted filesystem inside the clone is irrelevant because the clone itself is a short-lived artefact.
  2. Gap 2: the isolated VLAN. The clone lives on a VLAN with no route to any other VLAN on the lab. It can reach a single HTTP endpoint on the hypervisor host for task retrieval and result submission; it cannot reach the storage VLAN, the management VLAN, the trusted LAN, or any other VM. An nftables rule on the router enforces this with logged default-deny.
  3. Gap 3: zero WAN egress. The isolated VLAN has no default route to the internet. Any outbound connection attempted by the agent is dropped at the firewall and logged. If the agent needs a library, it pulls from a local mirror on the storage VLAN, but that mirror is reached via a one-way fetch proxy, and the agent cannot initiate the connection from inside the zone.

The layering matters. An escape from Gap 1 (the agent finds a hypervisor vulnerability and breaks out of the VM) lands in an isolated network with no route to anywhere interesting. An escape from Gap 2 (the agent finds a router misconfiguration) still cannot reach the internet. An escape from all three would mean a concurrent failure of the hypervisor, the router, and the firewall, which is the point of defence in depth.

The Action

A golden template, cloned on demand

The first ingredient is a Proxmox template with cloud-init enabled, hardened, and locked down. It lives on the hypervisor and is never booted for real work; it is only ever cloned.

# On the Proxmox host: download a minimal Ubuntu cloud image.
cd /var/lib/vz/template/iso
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img

# Create the template VM (one-time).
qm create 9000 --name hazmat-template --memory 2048 --cores 2 --net0 virtio,bridge=vmbr2,firewall=1,tag=50
qm importdisk 9000 jammy-server-cloudimg-amd64.img local-zfs
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-zfs:vm-9000-disk-0
qm set 9000 --ide2 local-zfs:cloudinit
qm set 9000 --boot c --bootdisk scsi0
qm set 9000 --serial0 socket --vga serial0

# Pre-seed the first-boot config via cloud-init snippet.
qm set 9000 --cicustom "user=local:snippets/hazmat-init.yaml"

# Convert to a template. It can no longer be started; only cloned.
qm template 9000

And a minimal hazmat-init.yaml:

#cloud-config
users:
  - name: agent
    sudo: false
    lock_passwd: true
    shell: /bin/bash

# No inbound services.
package_update: false
package_upgrade: false

runcmd:
  - systemctl disable --now ssh
  - systemctl disable --now unattended-upgrades

The spawn-and-reap orchestration

Each agent task is a clone, a run, a reap. A small shell script on the hypervisor handles the lifecycle:

#!/bin/bash
# /usr/local/sbin/hazmat-spawn.sh
set -euo pipefail

TEMPLATE_ID=9000
NEXT_ID=$(pvesh get /cluster/nextid)
TASK_ID="$1"
TIMEOUT_SECS=1800

echo "[$(date -Is)] Cloning template $TEMPLATE_ID to VM $NEXT_ID for task $TASK_ID"
qm clone "$TEMPLATE_ID" "$NEXT_ID" --name "hazmat-$TASK_ID" --full

# Inject task-specific cloud-init (task URL, result endpoint).
qm set "$NEXT_ID" --cicustom "user=local:snippets/task-$TASK_ID.yaml"

qm start "$NEXT_ID"

# Wait for the VM to signal completion (writes a file to a small
# shared volume) or hit the timeout.
timeout "$TIMEOUT_SECS" bash -c "
  while ! [ -f /srv/hazmat/done-$TASK_ID ]; do sleep 5; done
" || echo "[$(date -Is)] Task $TASK_ID timed out"

# Reap.
qm stop "$NEXT_ID" --timeout 30 || true
qm destroy "$NEXT_ID" --purge
rm -f "/srv/hazmat/done-$TASK_ID"
echo "[$(date -Is)] Reaped VM $NEXT_ID"

The script is boring. The boring part is the point: every successful run and every failed run end in the same state (no VM, no data, no persistent artefact except the logged result).

What broke

The first time the containment failed was not a security failure. It was an ergonomic one. The agent had been asked to compile a small Python package, and the spawn script cloned a fresh VM for the task. The compilation needed to download a dependency from the local mirror. The one-way fetch proxy was down that morning (unrelated maintenance), and the agent dutifully tried to fetch from the internet instead, failed at the firewall as designed, and returned the error “unable to install package cryptography”. I had no visibility into which stage of the pipeline failed, because my logging had been scoped to the agent’s own output, not to the containment boundaries.

The fix was a small Prometheus exporter on the firewall that surfaced a counter for “blocked egress attempts by source VLAN”. Any non-zero count on the Hazmat VLAN is now a log entry, a dashboard alert, and a line in the weekly report. The agent’s attempt to phone home, benign or not, became observable. Observability is what turns containment from theatre into infrastructure.

The principle

The three gaps are not redundant. Each is meant to fail independently. The cost of building all three is higher than building any one of them well, but the failure profile is fundamentally different: a single mistake in any gap is survivable because the other two still hold.

The principle generalises past AI. Any system in the lab that runs untrusted code (a CI runner that executes pull-request builds, a web service that accepts user uploads, a cron job that evaluates community-submitted expressions) deserves the same shape. You cannot make untrusted code trusted. You can only make its blast radius finite.

The hazmat bunker is the thing that lets me run agents without watching them. That is the deal: invisible containment for the cost of a golden template, a VLAN, three firewall rules, and a reap script. Cheap compared to the alternative, which is whatever a confident model does at 3 a.m. on a machine it should not be able to reach.

Footnotes

  1. NIST Special Publication 800-190 covers application container security considerations, including isolation and image-hygiene principles that apply equally to ephemeral VMs. nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-190.pdf. ↩

Table of Contents