Sandboxing & Isolation
Kernel Security Mechanisms · Security Fundamentals track
5 min read
In this module
Containing the Blast Radius
Even with all the kernel security mechanisms in the world, application-level vulnerabilities still happen. Sandboxing accepts this reality and focuses on limiting the damage: if a process is compromised, what can the attacker actually do? The answer, with good sandboxing, should be "almost nothing."
The Principle of Least Privilege
Every sandbox is built on the same principle: a process gets the minimum privileges it needs to function, and nothing else. A PDF renderer doesn't need network access. A video decoder doesn't need filesystem access. A JavaScript engine has no business loading kernel modules.
The challenge is implementing this at OS level, where the default is that processes can do almost anything their UID permits.
Chrome's Multi-Process Sandbox
Chrome is the gold standard for application sandboxing. It separates the browser into multiple process types, each with different privilege levels:
Browser process: Fully privileged. Handles file access, user input, and process management, and decides what every other process is allowed to do. This is the only process with broad system access.
Renderer processes: Heavily sandboxed. Each tab's web content runs in a renderer process that has almost no system access:
- On Linux: Seccomp-BPF restricts system calls to a minimal set. User namespaces provide filesystem and PID isolation. The process cannot open files, create network connections, or access hardware.
- On Windows: Restricted tokens remove most privileges. Job objects prevent creating child processes. Alternate desktop prevents UI interaction. The process runs at the Untrusted integrity level.
- On macOS: The Seatbelt sandbox profile restricts filesystem, network, and IPC access.
GPU process: Moderate sandboxing. Needs access to GPU hardware but not the filesystem.
Network process: Does the actual network I/O. Where it runs as a separate sandboxed process it gets network access and little else, but the sandbox varies by platform, and on some it still runs inside the browser process.
Every arrow in the diagram is a Mojo IPC channel. Notice that the renderers have no edge to the disk or the network: anything privileged they want, they have to ask the browser process for, and that message boundary is where a sandbox escape has to happen.
If an attacker exploits a vulnerability in the renderer (like a V8 JavaScript engine bug), they gain code execution within the sandbox but cannot access the filesystem, network, or other processes. They would need a sandbox escape - a second vulnerability in the IPC layer or operating system - to break out.
Modern browser exploits require at least two vulnerabilities: one to gain code execution in the renderer (the "entry bug") and one to escape the sandbox (the "escape bug"). This dramatically increases the cost of exploitation. A full Chrome exploit chain at Pwn2Own is worth hundreds of thousands of dollars, reflecting the difficulty of bypassing multiple layers of sandboxing.
OpenBSD: pledge() and unveil()
OpenBSD takes a uniquely pragmatic approach to sandboxing with two system calls that programs use to restrict themselves.
pledge() restricts which categories of system calls a process can make:
// After initialisation, restrict this web server to:// stdio: basic I/O (read, write, close)// inet: network operations// rpath: read-only filesystem accesspledge("stdio inet rpath", NULL);
// Any system call outside these categories kills the process with SIGABRT// Even if the attacker has code execution, they cannot:// - Write to the filesystem// - Execute other programs// - Create raw sockets// - Use ptraceunveil() restricts which filesystem paths a process can access:
// Only allow access to these pathsunveil("/var/www", "r"); // Read web contentunveil("/etc/ssl", "r"); // Read TLS certificatesunveil(NULL, NULL); // Lock the unveil list - no more paths can be added
// Access to any other path returns ENOENT (file not found)The beauty of pledge and unveil is their bluntness. Two lines of code after initialisation, and the kernel enforces the restrictions forever. The OpenBSD team has pledged the vast majority of the base system, so most programs self-sandbox without the developer lifting a finger.
FreeBSD Capsicum
Capsicum is a capability-based sandboxing framework that takes a different philosophical approach. Instead of listing what is forbidden, Capsicum programs enter "capability mode" where they can only operate on file descriptors they already hold. No new resources can be opened.
// Open all needed resources before entering capability modeint config_fd = open("/etc/myapp.conf", O_RDONLY);int log_fd = open("/var/log/myapp.log", O_WRONLY | O_APPEND);int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
// Enter capability modecap_enter();
// Now the process can ONLY use these three file descriptors// open(), connect(), bind(), and similar calls that create new resources FAIL// The process can read from config_fd, write to log_fd, and use socket_fd// but cannot open any new files or create any new network connectionsCapsicum's approach is powerful for data processing programs: open the input and output files, enter capability mode, then process data. Even if the processing code has a vulnerability, the attacker can only read from the input and write to the output.
Process Isolation Techniques Summary
Each sandboxing mechanism has different strengths:
| Mechanism | Granularity | Ease of Use | Platform |
|---|---|---|---|
| Seccomp-BPF | System call level | Complex | Linux |
| pledge/unveil | Category/path level | Simple | OpenBSD |
| Capsicum | File descriptor level | Moderate | FreeBSD |
| AppArmor | Path-based profiles | Moderate | Linux |
| Windows sandbox | Token/job-based | Complex | Windows |
| macOS Seatbelt | Profile-based | Moderate | macOS |
The best choice depends on the application and the platform. But the most important decision is to sandbox at all — any sandboxing is dramatically better than none.
A good sandbox answers the question: "If this process is completely compromised, what is the worst thing the attacker can do?" If the answer is "read one directory and write to one log file," the sandbox is working. If the answer is "everything root can do," the sandbox needs work.