AgentSkillsCN

vibecode-vm

利用 Apple 虚拟化框架构建并管理原生 macOS 虚拟机。创建 Alpine Linux ARM64 rootfs 镜像,下载内核,启动搭载 Valkey/PostgreSQL/OpenVSCode 服务的虚拟机,并管理虚拟机的生命周期。适用于构建虚拟机镜像、在原生环境中测试容器,或在 Apple Silicon 上运行隔离的 Linux 开发环境时使用。

SKILL.md
--- frontmatter
name: vibecode-vm
description: Build and manage native macOS VMs using Apple Virtualization Framework. Create Alpine Linux ARM64 rootfs images, download kernels, launch VMs with Valkey/PostgreSQL/OpenVSCode services, and manage VM lifecycle. Use when building VM images, testing containers natively, or running isolated Linux development environments on Apple Silicon.

VibeCode VM Skill

Build and manage native macOS VMs using Apple's Virtualization Framework (vfkit).

Quick Setup

bash
# Install vfkit and create directories
python3 scripts/vfkit/01-setup-vfkit.py

# Download Alpine Linux kernel
python3 scripts/vfkit/02-download-alpine-kernel.py

# Create Alpine rootfs with Node.js
python3 scripts/vfkit/03-create-alpine-rootfs.py

# Launch VM
python3 scripts/vfkit/04-launch-alpine-vm.py

Prerequisites

  • macOS 13+ (Ventura or later)
  • Apple Silicon (ARM64) or Intel Mac
  • Homebrew (for vfkit installation)
  • Python 3.10+

VM Manager CLI

The Python VM manager provides full lifecycle management:

bash
# List all VMs and their status
python3 scripts/vfkit/vm-manager.py list

# Start specific VM
python3 scripts/vfkit/vm-manager.py start valkey
python3 scripts/vfkit/vm-manager.py start postgresql
python3 scripts/vfkit/vm-manager.py start nodejs-dev

# Start all VMs
python3 scripts/vfkit/vm-manager.py start-all

# Stop VMs
python3 scripts/vfkit/vm-manager.py stop valkey
python3 scripts/vfkit/vm-manager.py stop-all

# Health check
python3 scripts/vfkit/vm-manager.py health

# Monitor resource usage
python3 scripts/vfkit/vm-manager.py monitor

# View/follow logs
python3 scripts/vfkit/vm-manager.py logs valkey
python3 scripts/vfkit/vm-manager.py follow valkey

Quick Reference

Setup Scripts

ScriptPurposeCommand
01-setup-vfkit.pyInstall vfkit, create directoriespython3 scripts/vfkit/01-setup-vfkit.py
02-download-alpine-kernel.pyDownload Alpine Linux kernelpython3 scripts/vfkit/02-download-alpine-kernel.py
03-create-alpine-rootfs.pyCreate Alpine rootfs with Node.jspython3 scripts/vfkit/03-create-alpine-rootfs.py
06-create-vibecode-rootfs.pyCreate full VibeCode rootfspython3 scripts/vfkit/06-create-vibecode-rootfs.py
07-create-persistent-vm.pyCreate persistent disk VMpython3 scripts/vfkit/07-create-persistent-vm.py

Launch Scripts

ScriptPurposeCommand
04-launch-alpine-vm.pyLaunch basic Alpine VMpython3 scripts/vfkit/04-launch-alpine-vm.py
05-launch-vibecode-vm.pyLaunch full VibeCode VMpython3 scripts/vfkit/05-launch-vibecode-vm.py
start-all-vms.pyStart all configured VMspython3 scripts/vfkit/start-all-vms.py
stop-all-vms.pyStop all running VMspython3 scripts/vfkit/stop-all-vms.py

Service VMs

ScriptPurposePortCommand
start-valkey.pyIn-memory cache (Redis-compatible)6379python3 scripts/vfkit/start-valkey.py
start-postgresql.pyPostgreSQL + pgvector5432python3 scripts/vfkit/start-postgresql.py
start-nodejs-dev.pyNode.js dev environment3000/5173/8080python3 scripts/vfkit/start-nodejs-dev.py

Testing & Validation

ScriptPurposeCommand
vm-health-check.pyCheck VM health statuspython3 scripts/vfkit/vm-health-check.py
test_all_vms.pyRun VM test suitepython3 scripts/vfkit/test_all_vms.py
verify_services.pyVerify services are runningpython3 scripts/vfkit/verify_services.py
test-valkey.pyTest Valkey connectivitypython3 scripts/vfkit/test-valkey.py

Interactive TUI Menu

For a guided experience, use the interactive menu:

bash
python3 scripts/vibecode_vm_menu.py

This provides:

  • VM status overview
  • Build initramfs (Ansible)
  • Build Swift app
  • Start/stop VMs
  • SSH connectivity
  • VSCode browser access
  • Network scanning

CLI Mode (Non-Interactive)

The menu also supports direct CLI commands:

bash
# Show VM status
python3 scripts/vibecode_vm_menu.py status -n

# Show help
python3 scripts/vibecode_vm_menu.py help -n

# Available commands
python3 scripts/vibecode_vm_menu.py --help

Commands: status, build, build-app, start, stop, ssh, vscode, clean, help, menu

Testing the TUI

bash
# Run TUI component tests
python3 scripts/vibecode_vm_menu.py --test

Build Scripts

Build Initramfs

bash
# Python initramfs builder (for Docker)
python3 scripts/build_initramfs.py

# K3s-enabled initramfs
python3 scripts/build_k3s_initramfs.py

Build VM Disk Images

bash
python3 scripts/create_vm_disk_images.py

Build Swift VM Manager

bash
# Compile Swift binary with entitlements
python3 scripts/build_vm_manager.py

Workflows

Create Development VM

bash
# Setup and create Alpine VM with Node.js
python3 scripts/vfkit/01-setup-vfkit.py
python3 scripts/vfkit/02-download-alpine-kernel.py
python3 scripts/vfkit/03-create-alpine-rootfs.py
python3 scripts/vfkit/04-launch-alpine-vm.py

Start Full Service Stack

bash
# Start Valkey, PostgreSQL, and Node.js dev VM
python3 scripts/vfkit/vm-manager.py start-all
python3 scripts/vfkit/vm-manager.py health

Test VM Performance

bash
python3 scripts/vfkit/basic_performance_test.py

Directory Structure

code
~/.vfkit/vms/vibecode-alpine/
├── kernel/     # Linux kernel files
├── rootfs/     # Root filesystem builds
│   └── build/  # Build working directory
├── disk/       # Persistent disk images
└── logs/       # VM console and error logs

~/VibeCode VMs/
└── *.bundle    # macOS VM bundles (SwiftUI apps)

Services Available in VMs

ServicePortCredentials
SSH22root / vibecode
Valkey (Redis)6379No auth
PostgreSQL5432vibecode / vibecode
OpenVSCode8080No auth
Vite Dev Server5173N/A
Node.js App3000N/A

Network

VMs use NAT networking on the 192.168.64.x subnet. DHCP assigns IPs automatically.

Scan for VM IPs:

bash
for i in {2..20}; do nc -zw1 192.168.64.$i 22 && echo "192.168.64.$i"; done

Troubleshooting

vfkit not found

bash
brew install vfkit

VM not starting

bash
# Check logs
python3 scripts/vfkit/vm-manager.py logs <vm-name>

# Check port availability
lsof -i :6379  # Valkey
lsof -i :5432  # PostgreSQL

Permission denied

Ensure vfkit has Virtualization entitlements:

bash
codesign -dv $(which vfkit)

Notes

  • Apple Silicon recommended - Native ARM64 VMs with near-native performance
  • Persistent storage - Use 07-create-persistent-vm.py for disk-backed VMs
  • Ansible integration - Full Ansible playbooks in ansible/ directory