@@ -359,7 +359,8 @@ with ws.branch("strategy_a") as a:
359359### Process isolation
360360
361361For untrusted or crash-prone agent code, ` BranchContext ` runs each task in
362- a sandboxed child process with its own filesystem view. No root needed.
362+ a sandboxed child process confined to its own branch via Landlock. No root
363+ needed.
363364
364365``` python
365366from branching import BranchContext
@@ -392,14 +393,14 @@ outcome = Speculate(candidates, isolate_processes=True, timeout=60)(ws)
392393
393394### Resource limits
394395
395- Constrain per-branch memory and CPU via cgroup v2 . Passing
396+ Constrain per-branch memory and CPU via setrlimit(2) . Passing
396397` resource_limits ` to any pattern automatically enables process isolation -
397- each branch runs in a forked child with cgroup enforcement .
398+ each branch runs in a forked child with limits enforced .
398399
399400``` python
400401from branching import ResourceLimits, BestOfN
401402
402- limits = ResourceLimits(memory = 512 * 1024 * 1024 , cpu = 0.5 ) # 512 MB, 50% CPU
403+ limits = ResourceLimits(memory = 512 * 1024 * 1024 , cpu_time = 30 ) # 512 MB, 30s CPU
403404
404405outcome = BestOfN(candidates, resource_limits = limits)(ws)
405406```
@@ -495,13 +496,20 @@ first-winner-commit semantics.
495496
496497You just create a ` Workspace ` pointed at a mounted BranchFS path.
497498
498- Process isolation (` BranchContext ` ) uses unprivileged Linux user namespaces
499- to give each child its own filesystem view. No root required - works on any
500- Linux distribution with ` unprivileged_userns_clone=1 ` (the default).
501-
502- Resource limits (` ResourceLimits ` ) use cgroup v2 to enforce per-branch
503- memory and CPU constraints. Each branch gets its own cgroup scope with
504- limits applied before the child process starts. Requires cgroup v2 with
505- the memory and cpu controllers enabled (the default on modern systemd
506- distributions).
499+ Process isolation (` BranchContext ` ) uses fork + Landlock LSM + BPF LSM to
500+ sandbox each child process. No namespaces, no cgroups, no root required:
501+
502+ - ** Landlock LSM** (Linux 5.13+) confines each child to its own branch.
503+ The child can read the filesystem outside the workspace but can only write
504+ under its branch path. Sibling branches and the mount root are denied.
505+ ` LANDLOCK_ACCESS_FS_REFER ` is included in the handled set so that
506+ rename/link across the branch boundary is blocked.
507+ - ** BPF LSM** provides inescapable process tracking. All descendants of a
508+ branched process inherit the branch ID, enabling atomic teardown of an
509+ entire branch's process tree. Requires ` CONFIG_BPF_LSM=y ` and
510+ ` lsm=...,bpf,... ` in the kernel command line.
511+ - ** setrlimit(2)** enforces per-branch resource limits (memory via
512+ ` RLIMIT_AS ` , CPU time via ` RLIMIT_CPU ` , process count via ` RLIMIT_NPROC ` ).
513+ Lightweight alternative to cgroups -- no cgroupfs infrastructure needed,
514+ limits are inherited by children on fork.
507515
0 commit comments