How Firejail Sandboxing Works in Linux
Firejail is an SUID security sandbox that reduces the risk of security breaches by isolating untrusted applications within restricted execution environments. It utilizes native Linux kernel security features—primarily namespaces, seccomp filtering, and capabilities—to constrain a program's access to files, networks, and system resources without requiring complex configuration or virtual machines.
Linux Namespaces
Firejail builds the foundation of its isolation using Linux namespaces. Namespaces partition kernel resources so that a process sees only its own isolated instance of a global resource.
- Mount Namespaces (CLONE_NEWNS): Firejail creates a
dedicated filesystem view for the sandboxed application. It can mount
clean
/tmpdirectories, hide sensitive user directories (such as~/.sshor~/.gnupg) using read-only mounts or temporary overlays, and replace system configuration files without altering the host filesystem. - Network Namespaces (CLONE_NEWNET): Applications can
run with an isolated network stack. Firejail can connect the sandbox to
a new virtual Ethernet interface, bridge, or loopback device, or
disconnect networking entirely using the
--net=noneoption. - PID Namespaces (CLONE_NEWPID): Process ID virtualization hides processes running on the host from the sandboxed application, preventing unauthorized inter-process inspection or signaling.
- IPC and UTS Namespaces: Firejail isolates Inter-Process Communication (IPC) to prevent shared-memory attacks, while UTS namespaces allow the sandbox to define independent hostnames and domain names.
System Call Filtering via Seccomp
To prevent applications from exploiting kernel vulnerabilities,
Firejail relies on Secure Computing Mode with Berkeley Packet Filters
(seccomp-bpf). By default or through application profiles, Firejail
drops access to dangerous or unnecessary system calls. Calls such as
ptrace (process tracing), sys_chroot,
kexec_load, and various obsolete or vulnerable legacy calls
are blocked. If a compromised application attempts to invoke a
restricted system call, the kernel immediately terminates the process or
returns an error.
Linux Capabilities Dropping
Linux splits traditional superuser privileges into distinct units
known as capabilities (via libcap). Although Firejail runs
with SUID privileges to configure namespaces and mounts, it drops these
elevated privileges before executing the target program. Furthermore,
Firejail strips standard user capabilities—such as
CAP_SYS_ADMIN, CAP_NET_ADMIN, and
CAP_RAW_IO—ensuring that even if a process achieves a local
privilege escalation within the sandbox, it cannot alter system-wide
settings or access hardware directly.
Filesystem Hardening and Private Directories
Beyond mount namespaces, Firejail implements explicit filesystem access controls:
- Blacklisting: Standard profiles automatically block read and write access to critical user data, password stores, and shell histories.
- Whitelisting: Firejail can enforce a strict model where only explicitly defined directories and files (such as an application's specific configuration directory) are visible inside the sandbox.
- Private and Overlay Filesystems: Firejail can instantiate temporary filesystems in RAM or use OverlayFS, ensuring that any file created, modified, or downloaded by the application is discarded upon exit.
Resource Allocation with Control Groups (cgroups)
Firejail integrates with Linux Control Groups (cgroups) to enforce hardware limits on sandboxed processes. Administrators can define maximum thresholds for CPU usage, memory consumption, and network bandwidth. This prevents a misbehaving or compromised process from launching Denial-of-Service (DoS) attacks against the host system.