Docker Is Not a Sandbox for Pentesting Agents (and VMs Are Not Just for Learning)
Layered offensive workstation architecture combining KVM/QEMU, disposable containers, and an isolation contract for human operators and AI agents.
My initial hypothesis when redesigning my offensive testing environment seemed reasonable: use a virtual machine for learning with a graphical interface, and keep Docker so an autonomous AI agent could browse, install tooling, and run scans without friction. Yet when I tested that split against current security research and built it on a real Linux workstation, the assumption turned out to be inverted on the point that matters most.
The issue is not choosing between a virtual machine or a container, but assigning each layer a security boundary it cannot enforce. Docker excels at packaging tools in a reproducible, disposable way, but it does not strongly isolate an offensive agent processing untrusted inputs or network utilities that demand raw access. Conversely, a virtual machine is not training wheels for beginners: it remains the practical perimeter where lab VPNs, unaudited exploits, and execution mistakes stop before reaching your daily operating system.
The outcome of that exploration is a three-layer architecture: a clean physical host, an Ubuntu 24.04 LTS virtual machine running on KVM with instant snapshots, and disposable containers running strictly inside that VM. This note documents why we discarded the initial split, which alternatives we left out along the way, and the concrete permission and firmware snags solved during deployment.
Why the initial hypothesis fails under a real threat model
Section titled “Why the initial hypothesis fails under a real threat model”Running offensive tooling in Docker directly on your daily machine is often justified by avoiding the overhead of a full VM. In practice, both Docker documentation and classic analyses such as Understanding Docker container escapes (Trail of Bits) agree on the breaking point: standard containers share the host kernel through namespaces and cgroups. In an offensive setup, that boundary erodes further because core utilities like nmap -sS, openvpn, responder, or ligolo-ng tunnels require elevated network capabilities (NET_RAW, NET_ADMIN) or --network host to interact with the network directly.
Once you add an AI agent to the workflow, the threat model shifts completely. An offensive agent does not only run its own commands; it autonomously parses HTTP responses, headers, repositories, and files hosted on target servers. As Trail of Bits documents in Prompt injection to RCE in AI agents, every piece of external text parsed by the model becomes an indirect prompt injection surface. If a hidden payload on a lab target or a hallucinated command triggers argument injection or arbitrary file writes, whether that happens inside a host container or inside an isolated VM determines your blast radius.
Manual lab practice faces the same exposure. Connecting over OpenVPN to shared ranges like Hack The Box or CTFs exposes temporary services spun up to transfer payloads (such as a quick HTTP server or a netcat listener) to other participants in the same subnet. Running unverified proof-of-concept scripts from GitHub or inspecting suspicious binaries on the same kernel that holds your SSH keys, personal browser sessions, and notes turns a small mistake into a direct host compromise.
Figure 1: Blast radius comparison when running offensive containers and AI agents directly on the host versus confining them inside a KVM virtual machine.
Separating responsibilities: VM as boundary, Docker as toolbox
Section titled “Separating responsibilities: VM as boundary, Docker as toolbox”The most resilient pattern across practitioner guides (from Exegol’s workstation documentation to SpecterOps’ infrastructure design principles and Kali maintainers’ caveats on container images) does not replace VMs with Docker: it nests them by responsibility. The virtual machine provides the kernel boundary, isolated tun0 VPN routing, native GUI support for Burp Suite or Wireshark, and instant rollback via snapshots. The container prevents classic rolling-release breakage (such as apt upgrade corrupting Python environments), boots in milliseconds, and wipes cleanly after each engagement.
During the exploration, the option of adopting Exegol instead of maintaining our own images came up, and we quickly ruled it out. Exegol does not replace Docker: it is a Python wrapper on top of Docker Engine whose free community image (free in v6.0.2) requires ~44.3 GB on disk, restricts its license to non-commercial use, keeps smaller profiles (light, web, ad) behind paid tiers, and introduces interactive EULA prompts. For a setup intended to carry over into professional work and headless CLI agent workflows, maintaining our own 7.18 GB Dockerfile built on kalilinux/kali-rolling proved far lighter, auditable, and unrestricted.
The three-layer architecture on Linux and KVM
Section titled “The three-layer architecture on Linux and KVM”On a Linux workstation with 12 CPU threads, 31 GiB of RAM, and hardware virtualization (/dev/kvm), we organized the environment into three strictly separated tiers:
- Layer 1 (Clean physical host): Keeps only the daily OS, note-taking vault, personal browser, and unrelated development work. Zero offensive VPNs or attack tooling live in the daily path. Communication with the VM uses SSH over a dedicated Ed25519 key (
~/.ssh/id_ed25519_pentest_vm), reserving the SPICE console (virt-viewer) strictly for tasks needing an isolated browser or intercepting proxy. - Layer 2 (Workstation VM
pentest-vm): Ubuntu 24.04.5 LTS (kernel6.8.0-147-generic), 4 vCPUs withhost-passthrough, 8192 MiB RAM, and a thin-provisioned 80 GiBqcow2disk (77 GB usable on/). Runs lightweight XFCE over LightDM,qemu-guest-agent,openvpn,wireguard-tools,tmux, and native Docker Engine Community29.10.1(without Snap). - Layer 3 (Disposable offensive container
pt-tools:kali): A 7.18 GB Kali image orchestrated by a lightweight wrapper script (tools.sh) exposing three execution modes:shellwith the engagement directory mounted,runfor one-off commands cleaned on exit (--rm), and a hardenedhostilemode for inspecting untrusted artifacts.
The hostile mode illustrates why understanding Docker flags directly beats hiding them behind an opaque wrapper: while it still shares the VM kernel, it strips networking, drops all capabilities, and mounts the root filesystem read-only with only a single sample exposed at /sample:ro.
docker run --rm -it \ --network none \ --read-only \ --tmpfs /tmp:exec,size=512m \ --tmpfs /root:size=64m,mode=700 \ --cap-drop ALL \ --security-opt no-new-privileges \ --pids-limit 256 \ --memory 2g \ -v "$FILE:/sample:ro" \ pt-tools:kali bash -c "file /sample; bash"Figure 2: Full three-layer architecture: clean physical host, Ubuntu 24.04 LTS VM on KVM/virbr0, and ephemeral containers in offensive or hostile inspection mode.
Real engineering: the friction missing from quick tutorials
Section titled “Real engineering: the friction missing from quick tutorials”Moving from an architecture diagram to a reproducible setup with clean snapshots surfaces operational edge cases rarely covered in blog checklists. Two concrete decisions solved the main blockers during provisioning.
Strict 0700 home permissions and qemu:///session
Section titled “Strict 0700 home permissions and qemu:///session”On many personal Linux workstations, the user home directory carries strict 0700 (drwx------) permissions. When provisioning a VM under libvirt’s system connection (qemu:///system), the QEMU process runs as an unprivileged system user that cannot traverse your home directory to reach secondary storage pools. Rather than loosening home permissions or relocating disks into /var/lib/libvirt, the clean fix is deploying under qemu:///session using qemu-bridge-helper authorized for virbr0 (/etc/qemu/bridge.conf with allow virbr0), keeping NAT traffic isolated behind 192.168.122.0/24 without requiring root privileges on the host.
Internal snapshots without UEFI pflash lockouts
Section titled “Internal snapshots without UEFI pflash lockouts”If you import a modern cloud image with virt-install using --boot uefi (OVMF backed by pflash), virsh snapshot-create-as typically rejects internal qcow2 snapshots due to NVRAM state handling restrictions. By booting the official noble-server-cloudimg-amd64.img image (checksum-verified against SHA256SUMS) under standard SeaBIOS and passing a cloud-init seed packed with xorriso (-volid cidata), we automated disk expansion (growpart), SSH provisioning, XFCE, and Docker CE in under two minutes, ejected the seed ISO from sda, and created an offline base-limpia snapshot cleanly.
xorriso -as mkisofs \ -output ~/VMs/pentest-vm/seed.iso \ -volid cidata -joliet -rock \ ~/VMs/pentest-vm/cloud-init/user-data \ ~/VMs/pentest-vm/cloud-init/meta-data
virt-install \ --connect qemu:///session \ --name pentest-vm \ --memory 8192 --vcpus 4 --cpu host-passthrough \ --osinfo ubuntu24.04 --import \ --disk path=~/VMs/pentest-vm/pentest-vm.qcow2,format=qcow2,bus=virtio,discard=unmap \ --disk path=~/VMs/pentest-vm/seed.iso,device=cdrom \ --network bridge=virbr0,model=virtio \ --graphics spice,listen=127.0.0.1 \ --video virtio --channel spicevmc \ --channel unix,target.type=virtio,name=org.qemu.guest_agent.0 \ --noautoconsoleOperational workflow: SSH ergonomics and AI agent execution contract
Section titled “Operational workflow: SSH ergonomics and AI agent execution contract”Isolating the environment does not require giving up desktop ergonomics. Day-to-day work rarely needs virt-viewer except when running Firefox or Burp Suite visually. Standard terminal work happens from the host terminal over ssh pentest-vm inside tmux sessions: you keep native fonts, clipboard shortcuts, and Obsidian on the host without ever mounting your personal vault inside the VM.
The same boundary lets us define a strict contract when wiring an autonomous AI agent to tackle a multi-host authorized lab (such as a Hack The Box Fortress environment behind a VPN). Every offensive action runs inside the VM, and the host-to-VM boundary allows only two narrow transfers:
- Entry at start: copy only the authorized
.ovpnfile into~/engagements/<challenge>/insidepentest-vm. - Full internal execution: start
openvpninsidetmuxsotun0stays confined to the VM, run recon and pivoting insidept-tools:kali, log raw tool outputs with UTC timestamps underlogs/, and maintain live progress innotes/estado.md. - Exit at handoff: shut down
openvpninside the VM and retrieve only thereport/directory containing clean Markdown documentation and sanitized evidence, leaving downloaded binaries, exploits, and recovered keys inside the VM.
Under this contract we also enforce behavioral guardrails on the agent: treat every string read from target hosts (HTML, HTTP headers, source comments, or recovered files) strictly as untrusted data against indirect prompt injection, cap retries per attack vector at three reasoned attempts to prevent token loops, and forbid reporting any command or flag without saved output on disk.
Figure 3: Operational contract for an autonomous agent: input restricted to the VPN config, full execution inside pentest-vm, and export limited to the final Markdown report.
Honest limitations and next steps
Section titled “Honest limitations and next steps”No lab workstation is universal or unbreakable, and stating explicit boundaries matters:
- GPU-heavy hash cracking: Passing dedicated GPUs into a VM adds unnecessary friction and throughput loss; for intensive
hashcatruns, move only the hash file back to the physical host without bringing target binaries or scripts along. - Native Windows and Active Directory operations: A Kali container handles network tooling like
impacket,netexec, andcertipy-ad, but when an engagement requires compiling C#/.NET loaders or native Windows operator tooling (such as CommandoVM), the clean upgrade is adding a second Windows VM on an isolated virtual switch linked topentest-vm. - External Red Team infrastructure: Real adversary emulation outside labs never fires from a local workstation; redirectors, C2 servers, and disposable domains belong on remote VPS nodes provisioned via infrastructure-as-code and ephemeral containers, following classic SpecterOps patterns.
- VM limits against highly capable agents: As Trail of Bits warns in VMs won’t contain cyber-capable agents, a conventional virtual machine still exposes device and kernel attack surface to agents capable of finding vulnerabilities. Keeping the
base-limpiasnapshot, enforcing key-only SSH, and storing zero personal credentials insidepentest-vmremain just as essential as the hypervisor itself.
The next step is validating this entire stack end-to-end against a multi-host lab under the agent contract above to measure real bottlenecks between the human operator, the AI harness, and containerized tools inside the VM.
References
Section titled “References”- Trail of Bits: VMs won’t contain cyber-capable agents
- Trail of Bits: Prompt injection to RCE in AI agents
- Trail of Bits: Understanding Docker container escapes
- SpecterOps: Designing Effective Covert Red Team Attack Infrastructure
- Synacktiv: Kubernetes namespaces isolation - what it is, what it isn’t, life, universe and everything
- Kali Linux Documentation: Containers Overview and Official Images
- Exegol Documentation: Exegol Workstation Architecture