NewThe Mac app is out for Apple SiliconGet it →
Fenzi
blog, safety

What is Linux Landlock?

Landlock is a Linux security module, in the kernel since version 5.13, that lets any process, root or not, restrict itself and every process it starts to the files it names and, on newer kernels, to the TCP ports it names. Once the limit is on, nothing inside can lift it. AI agent sandboxes use it to keep an agent to its project folder, but it knows ports, not hostnames, so it does not decide which sites the agent can reach.

By Boris Kwemo, , six-minute read

Landlock turns up wherever people sandbox an AI coding agent on Linux: in a sandbox's kernel requirements, in Codex's source, in small tools that wrap a command. This post explains what it is, how a process uses it, which agents rely on it, and what it leaves for something else to hold, from the kernel's own documentation and the agents' docs.

What Landlock is

Linux already decides what a user may touch, through file permissions and modules such as AppArmor and SELinux that an administrator configures. Landlock adds a layer that a program sets for itself. The kernel's Landlock documentation states its goal as the "restriction of ambient rights (e.g. global filesystem or network access) for a set of processes."

Ambient rights are everything a process can do because of who runs it. An agent started from your shell can read your home folder, your SSH keys and your other repositories, because you can. Landlock lets the launcher say, before the agent starts: this process and its children get the project folder and the system libraries, and nothing else.

It needs no root and no container. The same documentation calls it a stackable module, so it applies on top of the access controls a machine already has, and a process can only ever narrow what it is allowed.

How a process locks itself

It takes three system calls. A program creates a ruleset that lists the kinds of access it wants to control, such as reading files, writing files, executing or connecting over TCP. It adds rules that allow some of those on named folders or ports. Then it applies the ruleset to itself, and anything the ruleset controls but no rule allows is refused.

Before that last step an unprivileged process must set no_new_privs, so a set-user-ID program cannot hand it back the rights it just gave up. The limit then passes to every child process, the way a seccomp filter does. A shell script cannot get around it by starting another program.

Once a thread is landlocked, there is no way to remove its security policy; only adding more restrictions is allowed.Linux kernel docs, Landlock: unprivileged access control

You rarely write those calls yourself. landrun, a small open-source tool, wraps them in flags. This example from its README lets a client run from /usr and connect on three sets of ports, and refuses every other file and port:

landrun --rox /usr --connect-tcp 80,443,32000-32768 /usr/bin/my-client

What it can restrict

Landlock grows by versions of its interface, called ABI versions, and a program asks the running kernel which one it has. Linux 5.13 brought the first; landrun's README says TCP rules need Linux 6.7 or later. The main steps, from the kernel documentation:

ABIWhat a ruleset can control
1Reading, writing, executing, creating and removing files and folders under named paths
2Moving or linking a file from one folder to another
3Truncating a file
4Binding to and connecting on named TCP ports
5Device controls through ioctl on newly opened device files
6Abstract Unix sockets and signals to processes outside the sandbox
7Whether refusals are written to the kernel's audit log

Later versions add UDP ports and limits on Linux capabilities and namespaces. The documentation tells programs to take a best-effort approach: check the version and enforce whatever the running kernel supports. Keep that sentence in mind; it comes back below.

Where AI coding agents use it

Fewer agents use it directly than its reputation suggests. Each one picks its own Linux mechanism:

ToolLinux sandboxLandlock
Codexbubblewrap for files and namespaces, seccomp for system callsA legacy option, refused for policies that restrict the filesystem
Claude Code, with /sandbox onbubblewrap, a separate network namespace and a local proxyNot used
Gemini CLI, with --sandboxDocker, Podman, gVisor or LXCNot mentioned in its docs
landrunAny command you wrap, an agent includedThe whole mechanism

Codex's Linux sandbox README gives its reason for moving: the legacy Landlock option "cannot isolate app-server Unix sockets". Anthropic's page on the sandboxed Bash tool lists bubblewrap and socat as what Claude Code needs on Linux and WSL 2. Gemini CLI's sandbox docs run the agent in a container instead.

On a Mac there is no Landlock at all. Agents there use the macOS equivalent, macOS Seatbelt, or run inside a Linux VM, where Landlock applies to the VM's kernel. Our post on what a microVM is covers that second route.

Where it stops

Ports, not hosts. A network rule names a port. Allow port 443 and the process can connect to any server on the internet on 443, your API and a stranger's paste site alike. Sandboxes that care where an agent sends data pair Landlock or bubblewrap with a network namespace and an egress proxy that checks each hostname, as Claude Code does. Our notes on whether Claude Code can access the internet show why a host list matters.

Best effort can mean no sandbox. On a kernel without Landlock, or with Landlock turned off at boot, a best-effort program runs with fewer limits or none. landrun refuses by default when it cannot enforce an option you passed, and its --best-effort flag runs the command unsandboxed, with a warning, when Landlock is missing. Check which way your tool fails before you trust it.

Files outside the tree. The kernel documentation lists what it cannot restrict yet: pipes and sockets reached through /proc/<pid>/fd, and some special kernel filesystems, which it limits indirectly through its ptrace rules. A sandboxed process cannot mount filesystems, but it can still call chroot. A rule on one layer of an OverlayFS mount does not cover the merged view.

What you allowed. Landlock refuses what is outside the rules. Inside them it does nothing: a .env file in the project folder, a token in an environment variable, a writable shell startup file. Those are the cases our list of AI agent security risks starts with, and why the rules on what agentic AI security means cover hosts and keys as well as folders.

"Landlock is a sandbox."

Revision 1: it is the file and port layer of one. Namespaces, seccomp and a proxy hold the rest.

How to check it on your machine

Is it running? The kernel documentation gives the command, run as root. A line saying Landlock is up and running means the module loaded at boot.

dmesg | grep landlock || journalctl -kb -g landlock

Which version? A program reads the ABI version with one system call, as the documentation shows, and a sandbox that requires a minimum version should say so before it starts. If the module is missing, the documentation explains how to add landlock to the kernel's lsm= boot parameter.

Does it fail closed? Find out what your agent's sandbox does on a kernel without the version it needs: stop, or start anyway with a warning in a log nobody reads.

Test the refusals. Ask the agent to read a file under ~/.ssh and to fetch a host you did not allow. Both should fail. If the file read works, the folder rules are wider than you think; if the fetch works, the network is held by ports or by nothing.

A side note on how we do it

We build Fenzi, which starts the agent in an OpenShell sandbox where Landlock holds the folders, a network namespace sends traffic to a proxy that checks each host, seccomp blocks the sockets that would skip it, and the sandbox does not start if the kernel cannot enforce the folder rules; the kernel requirement on the install sheet gives the version. bubblewrap with a proxy, or a container with a host list, can answer the same question.

So, is Landlock enough?

Landlock is a real limit set in the kernel, it needs no root, and nothing inside can undo it, which makes it a good way to keep an AI agent to its folders. It is not a whole sandbox: it knows paths and ports, not hostnames or secrets, and a best-effort tool can quietly run without it. Use it for the files, put a host list in front of the network, keep keys out of the folders you allow, and make the sandbox refuse to start when the kernel falls short. The kernel's Landlock documentation, its current limitations section in particular, is the best next read.

One line to install.
One command to run.

curl -fsSL https://fenzi.dev/install.sh | sh

Then fenzi run claude. Ask it to open a pull request with the GitHub API, and watch the deny land.