Network Sandbox Engine (NSE)
NSE is a visual, deterministic firewall testing environment for nftables
rules.
Using ephemeral Linux network namespaces (netns) and Scapy packet injection, it
compiles and executes rules inside the real Linux kernel in total isolation.
The host firewall is never modified, providing a safe, scriptable, and visual platform for validating
complex routing logic, firewall policies, and traffic redirection behaviors.
veth), and injecting
raw packets (Scapy) requires kernel-level administration permissions.
The daemon and the CLI runner must be run with root privileges (e.g., using
sudo).
Key Features & Capabilities
- → Inject sequential list of packets via Scapy (e.g. simulating a TCP 3-way handshake).
- → Dynamic polling of
/proc/net/nf_conntrackto capture connection state changes.
- → Automatically spawns background echo servers on target ports inside namespaces.
- → Generates real kernel-level TCP responses to complete connections and update conntrack.
- → Spawn dual-namespace layouts simulating a Host ◄─► Router ◄─► Server topology.
- → Load and test transit forwarding rules on the intermediate Router namespace hook.
- → Interactive UI built with Svelte and FastAPI displaying real-time packet traces.
- → Detailed logs of nftables match hook evaluations, verdicts, and connection states.
Setup & Installation Instructions
Prerequisites
| Dependency | Purpose |
|---|---|
| Python 3.10+ | Runs the backend FastAPI, pipeline orchestration, and CLI test runner |
| Node.js 18+ | Required to compile the Svelte / Vite web interface (optional for CLI runner) |
| nftables | Required by the kernel to compile rules and trigger monitoring traces |
| conntrack | System utility required to read and poll `/proc/net/nf_conntrack` states |
1. Install Host Tools (Debian/Ubuntu)
2. Setup Python Virtual Environment
3. Running the Dashboard (Privilege Separation)
NSE version 1.1.0+ implements a privilege-separated architecture. Start the root execution daemon, the unprivileged API server, and the Vite frontend dev server in three separate terminals:
System Architecture
| Component | Technology | Description |
|---|---|---|
| Frontend UI | Svelte + Vite | Web interface containing the rule editor, packet sequence builder, and real-time conntrack/trace animation. |
| Execution Daemon (`nse-rootd`) | Python JSON-RPC | Runs as root. Exposes an isolated UNIX socket interface (/var/run/nse-core.sock) to handle low-level network namespace allocations,
Scapy packet injections, and trace harvesting. |
| Web Server (`nse-web`) | FastAPI | Runs as an unprivileged user. Interacts with the user interface via WebSockets and REST,
delegating low-level operations to the root daemon using RootdClient.
|
| Packet Injector | Scapy | Forges L2/L3 packets matching the requested protocol (TCP, UDP, ICMP, ICMPv6), injecting them directly onto virtual link endpoints. |
| Trace Harvester | `nft monitor trace` | Spawns as a background subprocess inside the target network namespace, parsing nftables tracing logs on-the-fly. |
| CLI Runner | Python argparse | Headless utility to parse, execute, and assert YAML-based test suites offline for CI/CD environments. |
Test Run Execution Flow
The lifecycle of a single sandbox test request follows a strict synchronous/asynchronous pipeline orchestrated by the daemon:
veth), and sets loopback devices UP.
meta nftrace set 1.nft monitor trace asynchronously to hook trace logs.nsenter.CLI Test Runner & YAML Suites
Automated assertions can be run inside headless environments using the nse-runner CLI:
Example YAML Suite (`test_suite.yaml`)
TTP (Transparent Tor Proxy) Integration Guide
NSE is officially integrated into TTP's pipeline to enable robust, offline verification of firewall rule behaviors (such as redirection and leak drop prevention) without requiring active Tor network circuits.
_run_nft_string() function. The resulting ruleset string is fed directly to NSE,
verifying that DNS queries are intercepted onto port 9054 and DNS-over-TLS (port 853) is rejected by the
killswitch.
Example Pytest Integration
Production Deployment & Releases
Release Packaging (`make release`)
Running make release runs linter and unit tests, compiles python distribution
package files (wheel and source distribution), copies deployment assets (like the Dockerfile and systemd
template), and signs the final release bundle containing the checksums using GPG.
Docker Container Deployment
To run the dashboard inside an isolated container with netns capabilities:
Known Limitations
meta skuid or meta skgid) will not trigger on injected
Scapy packets.
nft monitor trace support, which requires modern Linux Kernel
releases (Kernel 5.4+).
Running in restrictive VM or minimal container runtimes that block kernel module loading might cause
pipeline errors.