skillfed

landlock

Python interface to the Landlock Linux Security Module.

landlock v1.0.0.dev5 1.7M downloads/30d#3,612 on PyPI28
Permissive license Active released

What it is and what it does

Landlock is a Python wrapper around the Linux Landlock security module, which lets you restrict file system access at runtime by defining allow/deny rules. You create a Ruleset, specify which paths are accessible, call apply(), and from that point forward the process and its children cannot read, write, or interact with files outside the allowed set—even through symlinks or other escape routes. It supports Landlock ABI versions 1, 2, 3, and 5, covering initial access control, file renaming/linking, truncation, and device IOCTL operations.

The package is useful for hardening long-running services (like HTTP servers) against both accidental programming mistakes and exploits. If a vulnerability is discovered in your application, Landlock can prevent the attacker from reading sensitive files or accessing the full file system. It won't stop all malicious behavior, but it significantly raises the bar for post-exploitation damage. The implementation is straightforward: define rules declaratively, apply them once, and the kernel enforces them thereafter.

Use it for:

  • Harden HTTP or file servers to prevent symlink escapes and restrict access to a single directory.
  • Sandbox untrusted or third-party Python code to limit file system damage if it is compromised.
  • Protect sensitive application data by restricting access to configuration or credential files.
  • Enforce principle of least privilege in multi-tenant or containerized deployments.
  • Mitigate accidental file access bugs by explicitly declaring which paths an application may touch.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Landlock provides a Python interface to Linux's Landlock security module, enabling rule-based file system access restrictions to harden applications against unauthorized file access.

Yes, if you run Python on Linux and need file system sandboxing. The package is actively maintained, has no dependencies, installs easily, and solves a real security problem. The main constraint is that it requires Linux with Landlock kernel support (available in recent kernels) and Python >=3.9. Not applicable on other operating systems.

Install

landlock on PyPI

pip

pip install landlock

uv

uv add landlock

poetry

poetry add landlock

Installing landlock

Before you install

Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of 2026-08-10 with regular releases since first publication in 2022-08-21.

License in practice

MIT license (permissive) — you can use, modify, and distribute this package freely with minimal restrictions.

Quickstart

pip install landlock

from landlock import Ruleset

rs = Ruleset()
rs.allow(".")
rs.apply()

Requires Linux kernel with Landlock support; requires Python >=3.9.

Verify before relying

  • Whether Landlock ABI versions 4, 6, and 7 (marked unsupported) are planned for future release.
  • Performance overhead of Ruleset enforcement under typical application workloads.
  • Compatibility with specific Linux kernel versions and distributions.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 468 days since the last release
Last repo commit
First released
Downloads 1,724,754/month — #3,612 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: landlock-1.0.0.dev5-py3-none-any.whl

Development Status :: 3 - AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3 :: OnlyTopic :: SecurityTopic :: Software Development :: Libraries :: Python ModulesTopic :: System :: Operating System Kernels :: Linux

Tags

linux file system access controlsandboxing python applicationslandlock security modulerestrict file access pythonlinux security hardeningapplication sandboxingpermission-based file restrictions
linux-securitysandboxingaccess-control

More Python Modules packages