landlock
Python interface to the Landlock Linux Security Module.
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 landlockuv
uv add landlockpoetry
poetry add landlockInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
nono-pynono-py provides Python bindings for…
permissive · top 15,000 on PyPI
AccessControlAccessControl provides a security framework for…
unclear · top 15,000 on PyPI
pytest-socketA pytest plugin that blocks or restricts socket…
permissive · top 5,000 on PyPI
zope.securityProvides a generic security framework for…
unclear · top 15,000 on PyPI
redlock-pyImplements Redis-based distributed locks using…
permissive · top 15,000 on PyPI
authAn HTTP authorization service that answers…
permissive · top 15,000 on PyPI
pyseccomppyseccomp provides a pure-Python interface to…
permissive · top 5,000 on PyPI
fsProvides a unified filesystem abstraction layer…
permissive · top 5,000 on PyPI
rulesrules provides object-level permission checking…
permissive · top 15,000 on PyPI
django-pglockProvides Postgres advisory locks, table locks,…
permissive · top 5,000 on PyPI