A lightweight process isolation tool that utilizes Linux namespaces, cgroups, rlimits and seccomp-bpf syscall filters, leveraging the Kafel BPF language for enh
A lightweight process isolation tool that utilizes Linux namespaces, cgroups, rlimits and seccomp-bpf syscall filters, leveraging the Kafel BPF language for enh
Linux process isolation tool using namespaces, resource limits, and seccomp-bpf syscall filters.
chroot(), pivot_root(), read-only mounts, custom /proc and tmpfs# Install dependencies (Debian/Ubuntu)
sudo apt-get install autoconf bison flex gcc g++ git libprotobuf-dev libnl-route-3-dev libtool make pkg-config protobuf-compiler
git clone https://github.com/google/nsjail.git
cd nsjail
makedocker build -t nsjail .
docker run --privileged --rm -it nsjail nsjail --user 99999 --group 99999 --chroot / -- /bin/bash./nsjail -Mo --chroot / --user 99999 --group 99999 -- /bin/bash./nsjail -Ml --port 9000 --chroot /chroot --user 99999 --group 99999 -- /bin/sh -i./nsjail -Mr --chroot / -- /bin/echo "test"| Flag | Mode | Description |
|---|---|---|
-Ml |
LISTEN |
TCP server, fork process per connection |
-Mo |
ONCE |
Execute once, exit |
-Me |
EXECVE |
Direct execution without supervisor |
-Mr |
RERUN |
Execute repeatedly (useful for fuzzing) |
…NsJail uses Protocol Buffers for configuration. Schema: config.proto
…Load with:
./nsjail --config myconfig.cfgOverride command:
./nsjail --config myconfig.cfg -- /usr/bin/idIsolate networked services for security challenges:
./nsjail -Ml --port 8000 \
--chroot /srv/ctf \
--user 65534 --group 65534 \
--time_limit 60 \
--rlimit_as 128 \
--rlimit_cpu 10 \
-- /srv/ctf/challengeContinuously re-run potentially crashing programs:
./nsjail -Mr \
--chroot / \
--user 99999 \
--time_limit 10 \
--rlimit_as 512 \
--seccomp_string 'ALLOW { ... } DEFAULT KILL' \
-- /path/to/target @@Run untrusted GUI applications:
./nsjail --config configs/firefox-with-net-wayland.cfgRun program with minimal filesystem access:
./nsjail -Mo \
-R /lib/x86_64-linux-gnu \
-R /lib64 \
-R /usr/bin/find \
-R /dev/urandom \
-- /usr/bin/find /Uses pasta for userspace networking without root privileges:
./nsjail --user 1000 --group 1000 \
--use_pasta \
--chroot / \
-- /usr/bin/curl https://example.comOr via config:
user_net {
enable: true
ip: "10.255.255.2"
gw: "10.255.255.1"
ip6: "fc00::2"
gw6: "fc00::1"
tcp_ports: "80,443"
enable_dns: true
}Clone physical interface (requires root):
sudo ./nsjail \
--macvlan_iface eth0 \
--macvlan_vs_ip 192.168.1.100 \
--macvlan_vs_nm 255.255.255.0 \
--macvlan_vs_gw 192.168.1.1 \
-- /bin/bashKafel policy syntax:
./nsjail --seccomp_string '
POLICY example {
ALLOW {
read, write, open, close,
mmap, munmap, brk,
exit_group
}
DEFAULT KILL
}
USE example DEFAULT KILL
' -- /bin/program./nsjail \
--cgroup_mem_max $((512*1024*1024)) \
--cgroup_pids_max 32 \
--cgroup_cpu_ms_per_sec 800 \
-- /bin/cpu_intensive_programCLONE_NEWUSER required: Run with --disable_clone_newuser (requires root) or ensure user namespaces are enabled:
sysctl kernel.unprivileged_userns_clone # Should be 1Mount errors: Check that /proc is not overmounted:
cat /proc/mounts | grep /procCheck available namespaces:
ls -la /proc/self/ns/Disable unsupported namespaces (e.g., --disable_clone_newcgroup for kernel < 4.6).
Enable verbose logging:
./nsjail -v --config myconfig.cfgThis is not an official Google product.
No open issues yet, or sync has not completed.