ghostlan
ghostlan
ghostlan turns a single Linux machine into 1..N isolated virtual PCs ("ghosts") on a named virtual LAN—with live packet/network fault injection (tc netem), optional internet access (--nat), isolated per-ghost home/temp directories, headless virtual X11 displays (Xvfb + xdotool), and a built-in MCP server for AI agents.
Why ghostlan?
Testing distributed, P2P, media-transport, or desktop apps normally forces you into either:
Docker/VMs — painful for native GUI apps, GPU/audio, X11/Wayland, and fast iteration.
Manual
ip netnsbash scripts — fragile, requiresudoon every command, and leak namespaces/temp dirs on failure.
ghostlan runs native host binaries inside isolated Linux network namespaces (netns) connected via a Linux bridge, with:
Normal unprivileged user UID inside every ghost (no root GUI warnings).
Isolated
HOME,TMPDIR, andXDG_*directories per ghost (no/tmplockfile collisions).One-time
setcapsetup so both humans and LLM agents run withoutsudo.
Related MCP server: ContainerLab MCP Server
Use Cases
2-PC / P2P & Media Streaming Tests on One Machine: Test sender/receiver apps (OBS-to-OBS, VoIP, QUIC/UDP, LAN/mDNS discovery) under real packet loss, jitter, bandwidth caps, and cable unplug/replug (
link down/up).Autonomous LLM E2E Testing (No Babysitting): Designed from the ground up as an MCP server so any AI coding agent (Claude Code, Antigravity, Cursor, Claude Desktop, Windsurf) can run full multi-machine tests end-to-end without
sudoprompts or hijacking your real desktop.Multi-Instance Isolation Without Docker/VMs: Run multiple copies of desktop apps that normally collide on
/tmplockfiles,$HOME/XDG configs, ports, or PipeWire audio—at native speed.
How Autonomous LLM Testing Works (MCP-First)
Zero
sudoprompts: One-timeghostlan setup --mcpgrantssetcapand registersghostlan mcpacross your installed AI clients.Visual feedback loop: With
--gui, each ghost gets its own headlessXvfb -authdisplay. The agent callsghostlan_gui_screenshotand receives a native PNG directly in MCP, then drives dialogs withghostlan_gui_click/type/key.Deterministic waiting & filtering: Instead of brittle
sleep+grep, the agent usesghostlan_gui_wait_window,ghostlan_wait_log, andghostlan_logs(filter+since_line).Live fault injection: The agent calls
ghostlan_netem_set(loss/delay/jitter/rate),ghostlan_link(up/down), andghostlan_status(rx/tx/drop counters) mid-test, then cleans up withghostlan_down.
Requirements & One-Time Setup
Runtime Dependencies
Core: Linux kernel with
netns+nftables+tc netemGUI mode (
--gui):Xvfb,xdotool,import(ImageMagick), plus optionalopenbox(auto-started per display when installed for full window-manager focus/dialog support)Isolated audio (
--audio-null):pipewire,pipewire-pulse,pactl(each ghost gets its ownXDG_RUNTIME_DIR+ virtual null sink/mic, zero host audio bleed)
Quick Install (Pre-built Static Binary + setcap + MCP)
curl -fsSL https://raw.githubusercontent.com/saifmukhtar/ghostlan/main/install.sh | shBuild & Grant Capabilities (From Source)
go build -o ghostlan ./cmd/ghostlan
./ghostlan setup --mcpghostlan setup --mcp installs /usr/local/bin/ghostlan (0750, owned by root:<your-group>), prompts for sudo once to apply cap_net_admin,cap_sys_admin,cap_dac_override+ep, and registers ghostlan in detected MCP clients. After this, no sudo is needed at runtime.
Quick Start
# Create a named virtual LAN "openavx-test" with 2 ghosts (tx, rx),
# headless X11 displays (--gui), and 20ms latency + 5% packet loss defaults:
./ghostlan up openavx-test tx rx --gui --delay 20 --loss 5
# List active LANs
./ghostlan ls
# Check IPs, displays, link state, netem rules, and stats
./ghostlan status openavx-test --json
# Run a one-shot command inside tx
./ghostlan exec openavx-test tx -- ping -c 2 10.99.x.12
# Start a background server in rx and read its logs
./ghostlan start openavx-test rx -- python3 -m http.server 8080
./ghostlan logs openavx-test rx --tail 20
# Inject or clear live network faults
./ghostlan netem set openavx-test tx --loss 15 --delay 80 --jitter 10 --rate 2000
./ghostlan netem clear openavx-test tx
# Simulate unplugging/replugging an Ethernet cable
./ghostlan link down openavx-test rx
./ghostlan link up openavx-test rx
# Tear down everything cleanly (processes, Xvfb, netns, bridge, temp dirs)
./ghostlan down openavx-testShorthand: Any ghost-targeted command accepts either
<lan> <ghost>or<lan>/<ghost>(e.g.,ghostlan exec openavx-test/tx -- ...).
Command Reference
LAN Lifecycle
Command | What it does |
| Create a named LAN (defaults to |
| List all active virtual LANs. |
| Show ghost IPs, virtual displays, link state, active |
| Stop all tracked processes and |
Process & Command Execution
Command | What it does |
| Run a one-shot command inside the ghost's |
| Launch a detached background process inside the ghost; returns |
| Terminate a tracked background process ( |
| Read trailing or filtered |
| Poll a ghost's process log until a line matches |
Network Fault Injection
Command | What it does |
| Apply live |
| Remove active |
| Bring the ghost's |
| Bring the ghost's |
| Capture live packets on the ghost's host-side |
| Summarize |
Virtual X11 Display (--gui)
Command | What it does |
| List visible X11 windows, PIDs, geometries, and titles inside the ghost's |
| Poll until a window matching |
| Capture the ghost's virtual screen (or a specific window) to a PNG file. |
| Click at coordinates (screen-relative or window-relative). |
| Type text into the ghost's display or target window. |
| Send a key or combo (e.g., |
| Record a short MP4 video (and audio if |
| Compare two spaced frames to verify video motion vs frozen screen. |
Isolated Audio (--audio-null)
Command | What it does |
| Sample |
MCP Server (For AI Agents)
ghostlan includes a built-in Model Context Protocol (MCP) server exposing all operations as structured tools.
Stdio Transport (Default — Auto-Started by Any MCP Client)
Add to your MCP client config (Claude Desktop, Claude Code, Cursor, Antigravity, Zed, etc.):
{
"mcpServers": {
"ghostlan": {
"command": "/home/saif/ghostlan/ghostlan",
"args": ["mcp"]
}
}
}Streamable HTTP Transport (Optional)
./ghostlan mcp --http 127.0.0.1:8999(Always bind to 127.0.0.1, never 0.0.0.0, since ghostlan holds network capabilities.)
Available MCP Tools (24)
Diagnostics & LAN:
ghostlan_doctor,ghostlan_ls,ghostlan_up,ghostlan_status,ghostlan_downProcesses:
ghostlan_exec,ghostlan_start,ghostlan_stop,ghostlan_logs,ghostlan_wait_logNetwork & Capture:
ghostlan_netem_set,ghostlan_netem_clear,ghostlan_link,ghostlan_capture,ghostlan_capture_inspectGUI & Media:
ghostlan_gui_windows,ghostlan_gui_wait_window,ghostlan_gui_screenshot(returns native PNGImageContent+ path, optionalout_path),ghostlan_gui_click,ghostlan_gui_type,ghostlan_gui_key,ghostlan_gui_record,ghostlan_gui_motion,ghostlan_audio_check
Limitations, Quirks & Workarounds (For Agents)
Always run ghostlan_doctor (or ghostlan doctor) first on a new machine or whenever something fails—it immediately reports whether capabilities (setcap), Xvfb/xauth/xdotool/import, openbox, or pipewire/pactl are installed and ready.
No virtual webcam (
/dev/video*):--guiprovides an isolated X11 display (Xvfb) and--audio-nullprovides isolated PipeWire virtual audio sinks (ghostlan_sink,ghostlan_mic), not a V4L2 camera device. For synthetic video, use OBScolor_source/xshm_inputorffmpeg -f lavfi -i testsrc.Window Manager in
--gui: Ifopenboxorfluxboxis installed,ghostlanauto-starts it inside each ghost'sXvfb. If neither is installed,_NET_ACTIVE_WINDOWis unavailable andghostlanfalls back toxdotool windowfocus; ifEscape/dialog shortcuts don't work on a popup, take a screenshot and click the dialog button directly.No
wait_msonstart/exec: Useghostlan_wait_log(orghostlan wait-log) andghostlan_gui_wait_windowinstead of fixedsleepcalls.Raw socket tools (
tcpdumpinside ghost): Child processes run withPR_SET_NO_NEW_PRIVSas your unprivileged user, sotcpdumpwon't capture inside a ghost. Useghostlan capture start+ghostlan capture inspect(orghostlan_capture/ghostlan_capture_inspectin MCP) to capture on the host-sidevethand decode.pcapfiles instead. Unprivileged ICMPpingdoes work inside ghosts.netemunits & direction:--delayand--jittertake integer milliseconds (e.g.--delay 50, not50ms), andnetemapplies to egress on that ghost'seth0.
If Something Fails — What to Check First
Symptom / Error | What to Check First |
| Run |
| Run |
Popup/dialog ignores | Check |
App ignores config written to |
|
| Pass explicit |
| Run |
FAQ
1. Why setcap instead of sudo?
So AI agents and scripts can run ghostlan without password prompts, while apps launched inside ghosts still run as your normal unprivileged user ($UID)—not root.
2. Do --gui windows appear on my real desktop?
No. Each ghost gets its own headless Xvfb display (:99, :100, …) with WAYLAND_DISPLAY unset and X11 backends forced (QT_QPA_PLATFORM=xcb, GDK_BACKEND=x11, SDL_VIDEODRIVER=x11). Your real mouse, keyboard, and desktop are never touched. Use ghostlan gui screenshot (or ghostlan_gui_screenshot in MCP) to inspect the screen.
3. Does --gui work if my Linux desktop uses Wayland?
Yes. Xvfb is a standalone virtual X11 server, so xdotool and import work identically whether your host runs Wayland, X11, or a headless SSH session.
4. Can multiple virtual LANs run at the same time?
Yes. Each named LAN gets its own bridge (glbr-<hash>), unique veth names, non-overlapping /24 subnet (10.99.<n>.0/24), and isolated /tmp/ghostlan/<lan>/ state directory.
5. How does --nat work?--nat detects your default IPv4 uplink (or uses --uplink <iface>), configures a dedicated ghostlan_<lan> nftables masquerade/forward table, adds a default route inside each ghost, and bind-mounts a per-netns /etc/resolv.conf (1.1.1.1, 8.8.8.8) when processes run.
6. Where do apps store configs inside a ghost?
Each ghost isolates HOME, XDG_CONFIG_HOME (<home_dir>/config), XDG_DATA_HOME (<home_dir>/data), and TMPDIR (<home_dir>/tmp). Check xdg_config_home in ghostlan_up / ghostlan_status rather than writing to <home_dir>/.config.
7. Storage location choices (Default vs --private vs --dir):
Default (
/tmp/ghostlan/<lan>): Fasttmpfs(RAM-backed) with maximum temp space—best for normal single-user dev testing.--private($XDG_RUNTIME_DIR/ghostlan/<lan>,0700): Alsotmpfs(RAM-backed), locked to your user (0700)—best on shared/multi-user hosts or when handling sensitive tokens/configs.--dir <path>: Stores ghost directories under a custom path (e.g., SSD/disk)—best if a test writes multi-GB recordings or artifacts that won't fit intmpfs.Note for AI Agents / LLMs: Before calling
ghostlan_upfor a new test environment, ask the user which storage mode they prefer if they haven't specified one (default/tmpfor normal speed/space,--privatefor strict isolation, or--dir <path>for large files).
License
Dual-licensed under either of:
MIT License (LICENSE-MIT)
Apache License, Version 2.0 (LICENSE-APACHE)
at your option.
Available Tools
24 toolsghostlan_audio_checkA
Sample ghostlan_sink.monitor via ffmpeg volumedetect to measure dB levels and detect silence
Inputs: lan (required), ghost (required), duration_sec. Returns: max_db, silent, mean_db, duration_sec
ghostlan_captureA
Capture live packets on a ghost's host-side veth into a .pcap file (requires CAP_NET_RAW)
Inputs: lan (required), ghost (required), out_path, max_packets, +1 more. Returns: tcp, udp, icmp, bytes, +3 more
ghostlan_capture_inspectA
Summarize a saved .pcap file (packet/byte/TCP/UDP/ICMP counts + decoded lines via tcpdump -r)
Inputs: pcap_path (required), limit, filter. Returns: tcp, udp, icmp, bytes, +3 more
ghostlan_doctorA
Check host capabilities, kernel forwarding, and optional GUI/audio tools readiness
Returns: checks, wm_ready, gui_ready, core_ready, +1 more
ghostlan_downA
Stop all processes and displays and tear down a virtual LAN
Inputs: lan (required). Returns: message
ghostlan_execC
Run a one-shot command inside a ghost and capture stdout, stderr, and exit_code
Inputs: lan (required), ghost (required), command (required), env, +1 more. Returns: stderr, stdout, exit_code
ghostlan_gui_clickC
Click at coordinates inside a ghost's virtual display
Inputs: x (required), y (required), lan (required), ghost (required), +3 more. Returns: message
ghostlan_gui_keyB
Send a key or key combo (e.g. Return, ctrl+s, Escape) to a ghost's virtual display
Inputs: key (required), lan (required), ghost (required), window. Returns: message
ghostlan_gui_motionA
Compare two spaced frames on a ghost's virtual display to verify video motion vs frozen screen
Inputs: lan (required), ghost (required), interval_ms. Returns: moving, changed_pct, interval_ms
ghostlan_gui_recordC
Record a short MP4 video clip (and audio if audio_null=true) of a ghost's virtual display
Inputs: lan (required), ghost (required), out_path, duration_sec. Returns: video_path, duration_sec, audio_included
ghostlan_gui_screenshotA
Capture a PNG screenshot of a ghost's virtual display (or specific window) and return it as an image
Inputs: lan (required), ghost (required), window, out_path.
ghostlan_gui_typeC
Type text into a ghost's virtual display
Inputs: lan (required), text (required), ghost (required), window. Returns: message
ghostlan_gui_wait_windowA
Wait until a visible window matching title appears in a ghost's virtual display
Inputs: lan (required), ghost (required), title (required), timeout_sec. Returns: x, y, id, pid, +3 more
ghostlan_gui_windowsB
List visible X11 windows inside a ghost's virtual display
Inputs: lan (required), ghost (required). Returns: windows
ghostlan_linkA
Simulate Ethernet cable plug/unplug (link up/down) on a ghost
Inputs: up (required), lan (required), ghost (required). Returns: message
ghostlan_logsA
Read stdout/stderr log lines from a background process in a ghost (supports tail, since_line, and regex/substring filter)
Inputs: lan (required), ghost (required), tail, filter, +2 more. Returns: content, total_lines, matched_lines
ghostlan_lsC
List all active virtual LANs and their ghosts
Returns: lans
ghostlan_netem_clearB
Clear active netem impairments from a ghost
Inputs: lan (required), ghost (required). Returns: message
ghostlan_netem_setB
Apply live tc netem packet loss, delay, jitter, corruption, duplication, or bandwidth cap to a ghost
Inputs: lan (required), ghost (required), delay_ms, loss_pct, +4 more. Returns: message
ghostlan_startC
Start a detached background process inside a ghost
Inputs: lan (required), ghost (required), command (required), env. Returns: id, pid, status, command, +2 more
ghostlan_statusB
Get live status, IPs, displays, netem rules, interface counters, and process states for a LAN
Inputs: lan (required). Returns: gui, nat, name, bridge, +3 more
ghostlan_stopC
Stop a background process inside a ghost
Inputs: lan (required), ghost (required), proc_id (required). Returns: message
ghostlan_upB
Create a named virtual LAN with 1..N isolated ghosts, optional --nat, --gui (Xvfb), and default netem
Inputs: lan (required), dir, gui, nat, +9 more. Returns: gui, nat, name, bridge, +12 more
ghostlan_wait_logB
Poll a ghost's background process log until a line matches pattern or timeout expires
Inputs: lan (required), ghost (required), pattern (required), proc_id, +2 more. Returns: log_file, line_number, matched_line
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 24 tools
Each tool has a distinct resource and action: LAN lifecycle, process control, GUI input, GUI observation, audio, packet capture, and network impairment are cleanly separated. Adjacent tools like screenshot/record/motion and logs/wait_log are distinguishable by their descriptions and intended use.
All tools use the ghostlan_ prefix and snake_case, which is readable, but the suffixes mix bare verbs, nouns, abbreviations, and compound action names. There is no uniform verb_noun convention across the set.
24 tools is heavy for an MCP server, though the broad domain of virtual LANs, GUI automation, process control, and packet capture supports substantial surface area. Some niche tools could be consolidated, but most earn their place.
The set covers LAN lifecycle, process execution, GUI interaction, network impairment, capture inspection, audio checks, and diagnostics with few dead ends. Minor gaps exist around individual ghost management, file transfer, and richer GUI gestures.
Maintenance
Related MCP Connectors
Secure Linux sandboxes for AI agents, as MCP tools.
MCP server for Superserve sandboxes: create, exec, and manage Firecracker microVMs
Private networking for AI agents: networks, nodes, commands, files, services via hosted MCP.
20 DevOps/Linux MCP tools: Docker, systemd, seccomp, K8s, Terraform, Nginx, CI, cron, bash.
Related MCP Servers
- FlicenseAqualityBmaintenanceA virtual Linux desktop as an MCP server, shipped in Docker. Agents drive screen, mouse, keyboard across any GUI — browsers, IDEs, office suites, Wine/Windows apps, legacy software — many in parallel.12160-
- FlicenseNot gradedqualityDmaintenanceEnables network configuration, connectivity testing, and routing management for ContainerLab Linux containers through an MCP interface.3-
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to operate disposable Linux computers via MCP, providing tools for shell, file read/write, directory listing, and port exposure. It also supports browser automation and integration with any MCP-compatible client.Apache 2.0
- FlicenseNot gradedqualityAmaintenanceEnables security researchers to run network scanning, binary symbol and disassembly analysis, string extraction, and live or pcap traffic inspection through an MCP client, with optional Docker-based sandboxed command execution.-