CAPEv2 Auto Installer: Ubuntu Malware Sandbox Setup and Troubleshooting Guide
Published: · 10 min read · Cybersecurity
Nitiraj V. Kulkarni's CAPEv2 auto installer guide: Ubuntu setup, Windows agent provisioning, 24-stage recovery, non-PE analysis, and troubleshooting.
24
Deterministic stages
3
Provisioning phases
11
Diagnostic subsystems
1
Installer entry point
Why I Built This
Security tools are only useful when researchers can actually deploy and operate them. CAPEv2 is an open source platform for dynamic malware analysis, but its setup crosses several systems: Linux packages, KVM and libvirt, databases, Python environments, networking, Windows installation, and guest snapshots. I created the CAPEv2 auto installer to bring these moving parts into a repeatable installation and lifecycle workflow.
The problem is not just the number of commands. A missing virtualization flag can stop a guest from booting; a package lock can interrupt dependency installation; an agent that never starts can leave analysis tasks waiting. Without checkpoints and clear diagnostics, an interrupted setup is difficult to distinguish from a working lab. The project addresses that operational friction directly.
I did not want to accept it. So I built the CAPEv2 Universal Automated Installer and Malware Sandbox Orchestrator: an open source installation and lifecycle engine for Ubuntu hosts. It automates the host setup and base Windows installation, provides resume and repair tools, and documents the remaining guest-side configuration. This guide explains both the automation and the operator responsibilities, without treating a successful install as a guarantee of safe malware containment.
The Problem: Malware Sandbox Setup Has Too Many Failure Points
CAPEv2 gives you deep dynamic malware analysis: API call tracing, memory dumping, network capture, and payload extraction. But getting there manually means fighting five recurring failure modes:
Missing nested virtualization
The host lacks /dev/kvm exposure, so KVM guests refuse to start. Inside VirtualBox or VMware this requires manual hypervisor-specific fixes.
Package lock contention
Unattended upgrades hold /var/lib/dpkg/lock, and naive install scripts crash the moment apt cannot acquire the lock.
Python environment drift
System Python and dependency mismatches can derail deployment. The documented pipeline uses an isolated Python 3.12 environment with uv or poetry.
Manual Windows guest setup
The analysis VM requires clicking through the entire Windows installer over VNC, then configuring the guest agent by hand.
Brittle, non-resumable scripts
Existing helper scripts crash halfway through and leave the system in an unknown state, forcing a full manual restart.
These failures distract from the actual work: understanding malware behavior. My goal is to make setup progress observable and recovery repeatable, so infrastructure issues do not become an invisible barrier to analysis.
The Solution: A Deterministic 24-Stage State Machine
Instead of another brittle bash script, I designed the installer as a deterministic 24-stage state machine written in Python, with bash entry points. Every stage is idempotent, checkpointed, and resumable. If anything fails, the engine knows exactly where it stopped, repairs what it can, and picks up from the last good state.
The 24-stage deployment pipeline, condensed
- 1
Environment discovery
Detects KVM support, host resources, OS version, and virtualization flags automatically.
- 2
Dependency resolution
Refreshes repositories, resolves package locks, and prepares an isolated Python environment.
- 3
KVM / QEMU setup
Configures the hypervisor, libvirt, and the isolated analysis network.
- 4
ISO streaming
Downloads the official Microsoft Evaluation ISO from Microsoft's CDN with resume support.
- 5
Unattended Windows installation
Generates the OEMDRV answer disc and automates the base operating system installation.
- 6
Operator guest configuration
Run setup-agent.ps1 once as Administrator inside Windows, then restart the guest.
- 7
Handshake, snapshot & services
Waits for HTTP 200 on the guest agent, captures cape-clean in running state, and starts the CAPE services.
Every stage is idempotent, checkpointed, and resumable
Streaming ISO provisioning
Official Microsoft Evaluation ISOs are downloaded directly from Microsoft's CDN with live speed reporting and resume support. No more hunting for multi-gigabyte files.
Authentic Windows baseline
An OEMDRV answer disc automates base Windows setup with SATA and e1000e devices. The project requires genuine Windows and rejects stripped Tiny11 builds; guest configuration still requires one Administrator script run.
Self-healing and resume
repair.sh repairs snapshot issues, stale PID locks, routing, and daemons. install.sh --resume continues checkpointed deployment after reboots or interruptions.
Non-PE analysis readiness
enable-nonpe.sh stages archive tools, PDF readers, and script handlers, then snapshots the VM. The dedicated guide covers Office, WinRAR, 7-Zip, SumatraPDF, Java, AutoIt, and Node.js prerequisites.
Isolated analysis network
The default analysis network is 192.168.250.0/24 with isolated mode and internet routing disabled. Review host exposure and routing yourself; network separation is not a guarantee against every escape path.
11-subsystem diagnostics
diagnose.sh sweeps eleven subsystems and status.sh reports stage progression and configuration drift, so you always know the health of your deployment.
CAPEv2 Installation Guide: Host Setup, Windows Agent, and Verification
The README supports Ubuntu 24.04 and 22.04 LTS and lists Python 3.10+ for the orchestration engine. Use a dedicated lab host with hardware virtualization available. If Ubuntu is itself a VM, enable nested virtualization before installation. Do not run destructive commands on a host containing resources you need to preserve.
Step 1: Fresh installation
git clone https://github.com/NitirajKulkarni/capev2-auto-installer.git
cd capev2-auto-installer && chmod +x *.sh
sudo ./install.shThe installer also exposes a non-interactive mode for host-side automation. This does not remove the guest configuration step below:
sudo ./install.sh --non-interactiveStep 2: Automatic Windows ISO download
sudo ./install.sh --auto-download-isosudo ./clean-install.sh --windows-edition win11_eval --auto-download-isoTip: running inside VirtualBox or VMware? Stay with the default win10_eval, the README's recommended edition for nested hypervisors. The current configuration defaults to 3584 MB guest RAM and two vCPUs; adjust resources to your host and workload.
Step 3: Configure the Windows guest once
The current README explicitly requires an operator action because of Windows User Account Control and execution policy restrictions. Open the guest console, then open Windows PowerShell as Administrator. Run the supplied command inside this disposable analysis VM only; the setup script configures networking, disables Defender, and launches the CAPE agent.
virt-viewer -c qemu:///system cape-winSet-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force; $s = (Get-PSDrive -PSProvider FileSystem | ForEach-Object { Join-Path $_.Root 'setup-agent.ps1' } | Where-Object { Test-Path $_ } | Select-Object -First 1); if ($s) { & $s }
Restart-ComputerThe command searches mounted drives for setup-agent.ps1 rather than assuming the answer disc has a fixed drive letter. Restart after the script finishes so guest networking and agent startup take effect.
Step 4: Let the host verify and snapshot
The host waits for HTTP 200 from the agent at http://192.168.250.100:8000/, saves the cape-clean snapshot with active RAM in running state, and records it in /opt/CAPEv2/conf/kvm.conf. It starts cape-rooter, cape, cape-processor, and cape-web in dependency order. Check diagnostics before submitting any sample.
sudo ./diagnose.sh
sudo ./status.sh
sudo ./status.sh --driftThe pipeline includes an end-to-end validation stage, but the current configuration defaults submit_benign_sample to false. An installed service stack is not evidence that a sample was successfully analyzed; configure a benign test and verify its result before using the lab for real investigations.
Step 5: Resume after interruption
sudo ./install.sh --resumeStep 6: Clean reinstall only when needed
sudo ./clean-install.shThis removes previous VMs, disks, networks, the /opt/CAPEv2 directory, and all saved state before installing fresh. Back up anything you need first; this is not a routine repair command.
Configuration: One File Controls Everything
The entire deployment is driven by a single master file, config.toml:
[installation]
cape_root = "/opt/CAPEv2"
cape_user = "cape"
non_interactive = true
auto_repair = true
max_repair_attempts = 3
[network]
mode = "isolated"
subnet = "192.168.250.0/24"
gateway = "192.168.250.1"
vm_ip_start = "192.168.250.100"
libvirt_network_name = "cape-analysis"
web_port = 8000
[guest]
enabled = true
name = "cape-win"
windows_edition = "win10_eval"
auto_download_iso = true
disk_bus = "sata"
network_model = "e1000e"
disk_size_gb = 60
memory_mb = 3584
vcpus = 2
snapshot_name = "cape-clean"
install_timeout_minutes = 35This is an excerpt of the repository configuration, not the entire schema. The safety section defaults allow_internet_routing and allow_host_network_changes to false, and preserves unrelated libvirt VMs and networks. Review the complete configuration before changing networking, firewall, or repair permissions.
Before and After
Manual deployment
- Hours to days of setup
- VNC clicking through Windows setup
- Cryptic Python build failures
- No recovery from mid-install crashes
- Undocumented host prerequisites
With the auto installer
- One installer entry point with checkpoints
- Automated base OS, explicit guest setup step
- Isolated Python environment
- Resume and self-repair built in
- Isolated networking by default
After Installation: Non-PE Analysis and Daily Operations
A Windows guest that runs executables is not automatically ready for every document or archive. Non-PE analysis requires the appropriate applications and handlers. Use the repository's Non-PE Analysis Guide to prepare Office documents, archives, PDFs, Java, and script formats before interpreting a failed task as a harmless sample. Application installation and licensing requirements still apply.
sudo ./enable-nonpe.sh
sudo ./diagnose.sh --watch
sudo ./repair.shDiagnose first, inspect the findings, then repair. For recurring failures, the operator runbook and troubleshooting guide are the source of detailed procedures rather than repeatedly wiping the installation.
Troubleshooting CAPEv2: Agent, Snapshots, and Nested Virtualization
PowerShell appears frozen
The README identifies the QuickEdit trap: console text selection can pause execution. Press Esc, then Enter, and disable QuickEdit in PowerShell Properties. Confirm the script finishes before rebooting.
The host is waiting for the agent
Confirm the guest script ran as Administrator, restart Windows, and check the guest IP and port 8000 handshake. Use the FAQ for execution policy and answer-disc drive-letter issues.
Snapshot or KVM lock errors
Run diagnose.sh and consult the remediation guide for running snapshot states and stale locks. repair.sh covers these categories; manual snapshot deletion should follow the documented procedure, not guesswork.
Ubuntu has no /dev/kvm
Enable nested VT-x/AMD-V in VirtualBox or VMware; use CPU type host in Proxmox or expose virtualization extensions in Hyper-V. The Windows helper for VBS locks changes host security settings, so review the nested virtualization guide before using it.
Official CAPEv2 Auto Installer Documentation
Who This Is For
- Malware analysts who need a repeatable, disposable sandbox environment.
- SOC and incident response teams automating detonation pipelines in CI/CD.
- Threat intelligence researchers who want deterministic, reproducible analysis infrastructure.
- Students and educators learning dynamic malware analysis without days of setup friction.
What This Project Means to Me
Good security research should be reproducible, and reproducibility starts with infrastructure that researchers can inspect and reproduce. Releasing this installer under GPLv3 makes the orchestration, diagnostics, and recovery workflow available for review and improvement. The aim is a clearer path from an Ubuntu host to a usable lab, not a claim that every deployment is identical or automatically secure.
This work sits alongside my published research in cybersecurity and AI safety, and it reflects the same philosophy: find the friction that everyone has normalized, engineer it away properly, and share the result openly.
Get Started Today
The project is open source under GPLv3, supports Ubuntu 24.04 and 22.04 LTS, and is actively maintained. Start with the README, review the configuration, run the installer, complete guest setup, and verify the lab.
View capev2-auto-installer on GitHub
Stars, issues, and pull requests are welcome. If you deploy this in your lab or SOC, I would love to hear how it went. Follow Nitiraj V. Kulkarni on GitHub, explore my research publications, or use the contact page.
About the Author
Written by Nitiraj V. Kulkarni, AI safety and cybersecurity researcher based in Pune, India. Read full profile.