Skip to main content

Clone your workstation environment to an isolated VM with selective apps, paths and services

Project description

CloneBox ๐Ÿ“ฆ

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘     ____  _                    ____                   โ•‘
โ•‘    / ___|| |  ___   _ __   ___|  _ \  ___ __  __      โ•‘
โ•‘   | |    | | / _ \ | '_ \ / _ \ |_) |/ _ \\ \/ /      โ•‘
โ•‘   | |___ | || (_) || | | |  __/  _ <| (_) |>  <       โ•‘
โ•‘    \____||_| \___/ |_| |_|\___|_| \_\\___//_/\_\      โ•‘
โ•‘                                                       โ•‘
โ•‘      Clone your workstation to an isolated VM         โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

Clone your workstation environment to an isolated VM with selective apps, paths and services.

CloneBox lets you create isolated virtual machines with only the applications, directories and services you need - using bind mounts instead of full disk cloning. Perfect for development, testing, or creating reproducible environments.

Features

  • ๐ŸŽฏ Selective cloning - Choose exactly which paths, services and apps to include
  • ๐Ÿ” Auto-detection - Automatically detects running services, applications, and project directories
  • ๐Ÿ”— Bind mounts - Share directories with the VM without copying data
  • โ˜๏ธ Cloud-init - Automatic package installation and service setup
  • ๐Ÿ–ฅ๏ธ GUI support - SPICE graphics with virt-viewer integration
  • โšก Fast creation - No full disk cloning, VMs are ready in seconds

Installation

Quick Setup (Recommended)

Run the setup script to automatically install dependencies and configure the environment:

# Clone the repository
git clone https://github.com/wronai/clonebox.git
cd clonebox

# Run the setup script
./setup.sh

The setup script will:

  • Install all required packages (QEMU, libvirt, Python, etc.)
  • Add your user to the necessary groups
  • Configure libvirt networks
  • Install clonebox in development mode

Manual Installation

Prerequisites

# Install libvirt and QEMU/KVM
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager virt-viewer

# Enable and start libvirtd
sudo systemctl enable --now libvirtd

# Add user to libvirt group
sudo usermod -aG libvirt $USER
newgrp libvirt

# Install genisoimage for cloud-init
sudo apt install genisoimage

Install CloneBox

# From source
git clone https://github.com/wronai/clonebox.git
cd clonebox
pip install -e .

# Or directly
pip install clonebox

lub

# Aktywuj venv
source .venv/bin/activate

# Interaktywny tryb (wizard)
clonebox

# Lub poszczegรณlne komendy
clonebox detect              # Pokaลผ wykryte usล‚ugi/apps/ล›cieลผki
clonebox list                # Lista VM
clonebox create --config ... # Utwรณrz VM z JSON config
clonebox start <name>        # Uruchom VM
clonebox stop <name>         # Zatrzymaj VM
clonebox delete <name>       # Usuล„ VM

Quick Start

Interactive Mode (Recommended)

Simply run clonebox to start the interactive wizard:

clonebox

The wizard will:

  1. Detect running services (Docker, PostgreSQL, nginx, etc.)
  2. Detect running applications and their working directories
  3. Detect project directories and config files
  4. Let you select what to include in the VM
  5. Create and optionally start the VM

Command Line

# Create VM with specific config
clonebox create --name my-dev-vm --config '{
  "paths": {
    "/home/user/projects": "/mnt/projects",
    "/home/user/.config": "/mnt/config"
  },
  "packages": ["python3", "nodejs", "docker.io"],
  "services": ["docker"]
}' --ram 4096 --vcpus 4 --start

# List VMs
clonebox list

# Start/Stop VM
clonebox start my-dev-vm
clonebox stop my-dev-vm

# Delete VM
clonebox delete my-dev-vm

# Detect system state (useful for scripting)
clonebox detect --json

Usage Examples

Python Development Environment

clonebox create --name python-dev --config '{
  "paths": {
    "/home/user/my-python-project": "/workspace",
    "/home/user/.pyenv": "/root/.pyenv"
  },
  "packages": ["python3", "python3-pip", "python3-venv", "build-essential"],
  "services": []
}' --ram 2048 --start

Docker Development

clonebox create --name docker-dev --config '{
  "paths": {
    "/home/user/docker-projects": "/projects",
    "/var/run/docker.sock": "/var/run/docker.sock"
  },
  "packages": ["docker.io", "docker-compose"],
  "services": ["docker"]
}' --ram 4096 --start

Full Stack (Node.js + PostgreSQL)

clonebox create --name fullstack --config '{
  "paths": {
    "/home/user/my-app": "/app",
    "/home/user/pgdata": "/var/lib/postgresql/data"
  },
  "packages": ["nodejs", "npm", "postgresql"],
  "services": ["postgresql"]
}' --ram 4096 --vcpus 4 --start

Inside the VM

After the VM boots, mount shared directories:

# Mount shared paths (9p filesystem)
sudo mkdir -p /mnt/projects
sudo mount -t 9p -o trans=virtio,version=9p2000.L mount0 /mnt/projects

# Or add to /etc/fstab for permanent mount
echo "mount0 /mnt/projects 9p trans=virtio,version=9p2000.L 0 0" | sudo tee -a /etc/fstab

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     HOST SYSTEM                        โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ /home/user/  โ”‚  โ”‚  /var/www/   โ”‚  โ”‚   Docker     โ”‚  โ”‚
โ”‚  โ”‚  projects/   โ”‚  โ”‚    html/     โ”‚  โ”‚   Socket     โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚         โ”‚                 โ”‚                 โ”‚          โ”‚
โ”‚         โ”‚    9p/virtio    โ”‚                 โ”‚          โ”‚
โ”‚         โ”‚   bind mounts   โ”‚                 โ”‚          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚               CloneBox VM                        โ”‚  โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚  โ”‚
โ”‚  โ”‚  โ”‚ /mnt/proj  โ”‚ โ”‚ /mnt/www   โ”‚ โ”‚ /var/run/  โ”‚    โ”‚  โ”‚
โ”‚  โ”‚  โ”‚            โ”‚ โ”‚            โ”‚ โ”‚ docker.sockโ”‚    โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚  โ”‚
โ”‚  โ”‚                                                  โ”‚  โ”‚
โ”‚  โ”‚  cloud-init installed packages & services        โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick Clone (Recommended)

The fastest way to clone your current working directory:

# Clone current directory - generates .clonebox.yaml and asks to create VM
clonebox clone .

# Clone specific path
clonebox clone ~/projects/my-app

# Clone with custom name and auto-start
clonebox clone ~/projects/my-app --name my-dev-vm --run

# Clone and edit config before creating
clonebox clone . --edit

Later, start the VM from any directory with .clonebox.yaml:

# Start VM from config in current directory
clonebox start .

# Start VM from specific path
clonebox start ~/projects/my-app

Export YAML Config

# Export detected state as YAML (with deduplication)
clonebox detect --yaml --dedupe

# Save to file
clonebox detect --yaml --dedupe -o my-config.yaml

User Session & Networking

CloneBox supports creating VMs in user session (no root required) with automatic network fallback:

# Create VM in user session (uses ~/.local/share/libvirt/images)
clonebox clone . --user

# Explicitly use user-mode networking (slirp) - works without libvirt network
clonebox clone . --user --network user

# Force libvirt default network (may fail in user session)
clonebox clone . --network default

# Auto mode (default): tries libvirt network, falls back to user-mode if unavailable
clonebox clone . --network auto

Network modes:

  • auto (default): Uses libvirt default network if available, otherwise falls back to user-mode (slirp)
  • default: Forces use of libvirt default network
  • user: Uses user-mode networking (slirp) - no bridge setup required

Commands Reference

Command Description
clonebox Interactive VM creation wizard
clonebox clone <path> Generate .clonebox.yaml from path + running processes
clonebox clone . --run Clone and immediately start VM
clonebox clone . --edit Clone, edit config, then create
clonebox clone . --user Clone in user session (no root)
clonebox clone . --network user Use user-mode networking (slirp)
clonebox clone . --network auto Auto-detect network mode (default)
clonebox start . Start VM from .clonebox.yaml in current dir
clonebox start <name> Start existing VM by name
clonebox stop <name> Stop a VM (graceful shutdown)
clonebox stop -f <name> Force stop a VM
clonebox delete <name> Delete VM and storage
clonebox list List all VMs
clonebox detect Show detected services/apps/paths
clonebox detect --yaml Output as YAML config
clonebox detect --yaml --dedupe YAML with duplicates removed
clonebox detect --json Output as JSON

Requirements

  • Linux with KVM support (/dev/kvm)
  • libvirt daemon running
  • Python 3.8+
  • User in libvirt group

Troubleshooting

Network Issues

If you encounter "Network not found" or "network 'default' is not active" errors:

# Option 1: Use user-mode networking (no setup required)
clonebox clone . --user --network user

# Option 2: Run the network fix script
./fix-network.sh

# Or manually fix:
virsh --connect qemu:///session net-destroy default 2>/dev/null
virsh --connect qemu:///session net-undefine default 2>/dev/null
virsh --connect qemu:///session net-define /tmp/default-network.xml
virsh --connect qemu:///session net-start default

Permission Issues

If you get permission errors:

# Ensure user is in libvirt and kvm groups
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER

# Log out and log back in for groups to take effect

VM Already Exists

If you get "domain already exists" error:

# List VMs
clonebox list

# Stop and delete the existing VM
clonebox delete <vm-name>

# Or use virsh directly
virsh --connect qemu:///session destroy <vm-name>
virsh --connect qemu:///session undefine <vm-name>

virt-viewer not found

If GUI doesn't open:

# Install virt-viewer
sudo apt install virt-viewer

# Then connect manually
virt-viewer --connect qemu:///session <vm-name>

License

MIT License - see LICENSE file.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clonebox-0.1.5.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clonebox-0.1.5-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file clonebox-0.1.5.tar.gz.

File metadata

  • Download URL: clonebox-0.1.5.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for clonebox-0.1.5.tar.gz
Algorithm Hash digest
SHA256 29ef3cc7a11f3eaf8f9c444786a4fecb570d476ea641091aa3dcf8810486147c
MD5 6954ac81045279053860e392cba43847
BLAKE2b-256 58245445c1ea3d40354308aee05609c2dbc4c9237ead4797799a96fc1cebfdf9

See more details on using hashes here.

File details

Details for the file clonebox-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: clonebox-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for clonebox-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 364a41e3fca14adc9643a32554f64791eb32bdc754c488f72d601ff6090da625
MD5 ea03e1d35ce414235928fdf7cea06e01
BLAKE2b-256 d77ade27bdbfc621a598158d28319e034441b502bd286634298db6ce393e532f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page