NSJAIL(1)
π nsjail β process isolation tool for linux
okay bestie, listen up: this is the manual page for nsjail, section 1 of the User Commands series. it's a whole jail for your processes. get comfy. π«Ά
πΈ NAME
nsjail β process isolation tool for linux
β¨ SYNOPSIS
nsjail [options] -- path_to_command [args]
π¦ DESCRIPTION
So like. NsJail is a process isolation tool for Linux. it literally uses the Linux namespace subsystem, resource limits, and the seccomp-bpf syscall filters of the Linux kernel to lock your little guy up in a sandbox. it's giving maximum security, minimum escape. π₯
π Options
okay this is the long part. every single flag is here, i promise. no skipping. π
--help,-hβ Help plz.. (that's literally the whole description, bestie, they said what they said π)--mode,-MVALUE β how should the jail run?? (default:o[MODE_STANDALONE_ONCE]). your choices are:lβ Wait for connections on a TCP port (specified with--port) [MODE_LISTEN_TCP]oβ Launch a single process on the console usingclone/execve[MODE_STANDALONE_ONCE]eβ Launch a single process on the console usingexecve[MODE_STANDALONE_EXECVE]rβ Launch a single process on the console withclone/execve, keep doing it forever [MODE_STANDALONE_RERUN]
--config,-CVALUE β Configuration file in theconfig.protoProtoBuf format (go peek at theconfigs/directory for examples π)--exec_file,-xVALUE β File to exec (default:argv[0])--execute_fdβ Useexecveat()to execute a file-descriptor instead of executing the binary path. in that caseargv[0]/exec_filedenotes a file path before mount namespacing--chroot,-cVALUE β Directory containing/of the jail (default: none)--rwβ Mount chroot dir (/) R/W (default: R/O). careful, you're unlocking the write permission bestie π--user,-uVALUE β Username/uid of processes inside the jail (default: your current uid). you can also use theinside_ns_uid:outside_ns_uid:countconvention here. can be specified multiple times π--group,-gVALUE β Groupname/gid of processes inside the jail (default: your current gid). you can also use theinside_ns_gid:global_ns_gid:countconvention here. can be specified multiple times π--hostname,-HVALUE β UTS name (hostname) of the jail (default:'NSJAIL')--cwd,-DVALUE β Directory in the namespace the process will run (default:'/')--port,-pVALUE β TCP port to bind to (enablesMODE_LISTEN_TCP) (default:0)--bindhostVALUE β IP address to bind the port to (only in [MODE_LISTEN_TCP]), (default:'::')--max_connsVALUE β Maximum number of connections across all IPs (only in [MODE_LISTEN_TCP]), (default:0(unlimited))--max_conns_per_ip,-iVALUE β Maximum number of connections per one IP (only in [MODE_LISTEN_TCP]), (default:0(unlimited))--log,-lVALUE β Log file (default: uselog_fd)--log_fd,-LVALUE β Log FD (default:2)--time_limit,-tVALUE β Maximum time that a jail can exist, in seconds (default:600)--max_cpusVALUE β Maximum number of CPUs a single jailed process can use (default:0'no limit')--daemon,-dβ Daemonize after start π»--verbose,-vβ Verbose output (it will yap. a lot.)--quiet,-qβ Log warning and more important messages only--really_quiet,-Qβ Log fatal messages only. silent treatment mode π--keep_env,-eβ Pass all environment variables be passed process (default: all envars are cleared)--env,-EVALUE β Additional environment variable (can be used multiple times). if the envar doesn't contain'='(e.g. just the'DISPLAY'string), the current envar value will be used β¨--keep_capsβ Don't drop any capabilities π₯--capVALUE β Retain this capability, e.g.CAP_PTRACE(can be specified multiple times)--silentβ Redirect child process'fd:0/1/2to/dev/null--stderr_to_nullβ RedirectFD=2(STDERR_FILENO) to/dev/null--skip_setsidβ Don't callsetsid(), allows for terminal signal handling in the sandboxed process. Dangerous β οΈ like fr, they put it in the manpage for a reason--pass_fdVALUE β Don't close this FD before executing the child process (can be specified multiple times), by default:0/1/2are kept open--disable_no_new_privsβ Don't set theprctl(NO_NEW_PRIVS, 1)(DANGEROUS) π bestie please--rlimit_asVALUE βRLIMIT_ASin MB,'max'or'hard'for the current hard limit,'def'or'soft'for the current soft limit,'inf'forRLIM_INFINITY(default:4096)--rlimit_coreVALUE βRLIMIT_COREin MB,'max'or'hard'for the current hard limit,'def'or'soft'for the current limit,'inf'forRLIM_INFINITY(default:0)--rlimit_cpuVALUE βRLIMIT_CPU,'max'or'hard'for the current hard limit,'def'or'soft'for the current soft limit,'inf'forRLIM_INFINITY(default:600)--rlimit_fsizeVALUE βRLIMIT_FSIZEin MB,'max'or'hard'for the current hard limit,'def'or'soft'for the current soft limit,'inf'forRLIM_INFINITY(default:1)--rlimit_nofileVALUE βRLIMIT_NOFILE,'max'or'hard'for the current hard limit,'def'or'soft'for the current limit,'inf'forRLIM_INFINITY(default:32)--rlimit_nprocVALUE βRLIMIT_NPROC,'max'or'hard'for the current hard limit,'def'or'soft'for the current soft limit,'inf'forRLIM_INFINITY(default:'soft')--rlimit_stackVALUE βRLIMIT_STACKin MB,'max'or'hard'for the current hard limit,'def'or'soft'for the current soft limit,'inf'forRLIM_INFINITY(default:'soft')--disable_rlimitsβ Disable all rlimits, default to limits set by parent--persona_addr_compat_layoutβpersonality(ADDR_COMPAT_LAYOUT)--persona_mmap_page_zeroβpersonality(MMAP_PAGE_ZERO)--persona_read_implies_execβpersonality(READ_IMPLIES_EXEC)--persona_addr_limit_3gbβpersonality(ADDR_LIMIT_3GB)--persona_addr_no_randomizeβpersonality(ADDR_NO_RANDOMIZE)--disable_clone_newnet,-Nβ Don't useCLONE_NEWNET. Enable global networking inside the jail π (networking girlies stay winning)--disable_clone_newuserβ Don't useCLONE_NEWUSER. Requireseuid==0--disable_clone_newnsβ Don't useCLONE_NEWNS--disable_clone_newpidβ Don't useCLONE_NEWPID--disable_clone_newipcβ Don't useCLONE_NEWIPC--disable_clone_newutsβ Don't useCLONE_NEWUTS--disable_clone_newcgroupβ Don't useCLONE_NEWCGROUP. Might be required for kernel versions < 4.6 β--uid_mapping,-UVALUE β Add a custom uid mapping of the forminside_uid:outside_uid:count. setting this requiresnewuidmap(set-uid) to be present--gid_mapping,-GVALUE β Add a custom gid mapping of the forminside_gid:outside_gid:count. setting this requiresnewgidmap(set-uid) to be present--bindmount_ro,-RVALUE β List of mountpoints to be mounted--bind(ro) inside the container. can be specified multiple times. supports'source'syntax, or'source:dest'--bindmount,-BVALUE β List of mountpoints to be mounted--bind(rw) inside the container. can be specified multiple times. supports'source'syntax, or'source:dest'--tmpfsmount,-TVALUE β List of mountpoints to be mounted as tmpfs (R/W) inside the container. can be specified multiple times. supports'dest'syntax. alternatively, use-m none:dest:tmpfs:size=8388608π--mount,-mVALUE β Arbitrary mount, formatsrc:dst:fs_type:options--symlink,-sVALUE β Symlink, formatsrc:dst--disable_procβ Disable mounting procfs in the jail--proc_pathVALUE β Path used to mount procfs (default:'/proc')--proc_rwβ Is procfs mounted as R/W (default: R/O)--seccomp_policy,-PVALUE β Path to file containing seccomp-bpf policy (seekafel/)--seccomp_stringVALUE β String with kafel seccomp-bpf policy (seekafel/)--seccomp_logβ UseSECCOMP_FILTER_FLAG_LOG. log all actions exceptSECCOMP_RET_ALLOW. supported since kernel version4.14π--cgroup_mem_maxVALUE β Maximum number of bytes to use in the group (default:'0'- disabled)--cgroup_mem_memsw_maxVALUE β Maximum number of memory+Swap bytes to use in the group (default:'0'- disabled)--cgroup_mem_swap_maxVALUE β Maximum number of swap bytes to use in the group (default:'-1'- disabled)--cgroup_mem_mountVALUE β Location of memory cgroup FS (default:'/sys/fs/cgroup/memory')--cgroup_mem_parentVALUE β Which pre-existing memory cgroup to use as a parent (default:'NSJAIL')--cgroup_pids_maxVALUE β Maximum number of pids in a cgroup (default:'0'- disabled)--cgroup_pids_mountVALUE β Location of pids cgroup FS (default:'/sys/fs/cgroup/pids')--cgroup_pids_parentVALUE β Which pre-existing pids cgroup to use as a parent (default:'NSJAIL')--cgroup_net_cls_classidVALUE β Class identifier of network packets in the group (default:'0'- disabled)--cgroup_net_cls_mountVALUE β Location of net_cls cgroup FS (default:'/sys/fs/cgroup/net_cls')--cgroup_net_cls_parentVALUE β Which pre-existing net_cls cgroup to use as a parent (default:'NSJAIL')--cgroup_cpu_ms_per_secVALUE β Number of milliseconds of CPU time per second that the process group can use (default:'0'- no limit)--cgroup_cpu_mountVALUE β Location of cpu cgroup FS (default:'/sys/fs/cgroup/net_cls') π yes that's what it says, i'm not touching it--cgroup_cpu_parentVALUE β Which pre-existing cpu cgroup to use as a parent (default:'NSJAIL')--cgroupv2_mountVALUE β Location of cgroup v2 directory (default:'/sys/fs/cgroup')--use_cgroupv2β Use cgroup v2 β¨--iface_no_loβ Don't bring the'lo'interface up--iface_ownVALUE β Move this existing network interface into the new NET namespace. can be specified multiple times--macvlan_iface,-IVALUE β Interface which will be cloned (MACVLAN) and put inside the subprocess' namespace as'vs'--macvlan_vs_ipVALUE β IP of the'vs'interface (e.g."192.168.0.1")--macvlan_vs_nmVALUE β Netmask of the'vs'interface (e.g."255.255.255.0")--macvlan_vs_gwVALUE β Default GW for the'vs'interface (e.g."192.168.0.1")--macvlan_vs_maVALUE β MAC-address of the'vs'interface (e.g."ba:ad:ba:be:45:00") π iconic
(part 1 of 2 β the rest of the flags are in part 2, keep reading bestie π)
β¨ EXAMPLES β¨
okay bestie, this is the part where it all comes together π«Ά four little snippets, and honestly? they ate. copy these, run these, live your truth.
πΈ wait on a port and hand over a shell
Wait on a port 31337 for connections, and run /bin/sh:
nsjail -Ml --port 31337 --chroot / -- /bin/sh -i
that's the whole vibe: it hangs out on 31337, and when someone connects it spawns /bin/sh for them. lowkey iconic. π
π¦ re-run a command as a sub-process
Re-run the echo command as a sub-process:
nsjail -Mr --chroot / -- /bin/echo "ABC"
-Mr keeps bringing it back, over and over, as a sub-process. it's giving "again, and again, and again" energy πβ¨
π run it exactly once, as a sub-process
Run the echo command once only, as a sub-process:
nsjail -Mo --chroot / -- /bin/echo "ABC"
yep β the -Mo version does the thing once, as a sub-process, and then it's done. no reruns, no drama. periodt. π₯
β no supervisor at all, just send it
Execute the echo command directly, without a supervising process:
nsjail -Me --chroot / --disable_proc -- /bin/echo "ABC"
-Me means it runs the command directly β no supervising process hovering over it. and bestie, notice the --disable_proc in there? that's just how this example rolls. main character energy fr fr π
π ngl these four are your whole starter pack β port mode, re-run mode, once mode, and direct mode. pick your fighter, keep the flags exactly as written, and you're golden β¨
and that's the whole page, bestie β you made it π this is nsjail, page NSJAIL(1), dated August 2017 β go forth, sandbox responsibly, and remember: the vibe changes, the flags never do ππ
mwah π β see you in the next manpage, iykyk
π¦ where this page comes from
- alpine 3.24: nsjail-doc 3.6-r1 Β· Apache-2.0
- nixos 26.05: nsjail 3.6
- nixpkgs unstable: nsjail 3.6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms