procage 0.4.0

Process sandboxing for Rust on macOS (Seatbelt, without sandbox-exec) and Linux (Landlock, seccomp, namespaces)
Documentation
# procage

๐Ÿ›ก๏ธ **Process sandboxing for Rust.** procage runs a child process in an OS
sandbox on macOS (Seatbelt, without the deprecated `sandbox-exec`) and on
Linux (Landlock, seccomp and namespaces). No helper binaries, no root.

It is built for programs that run commands on someone else's behalf: coding
agents, MCP servers, build orchestrators. The code inside the child runs with
your user id, whether it is an LLM following injected instructions or a
project's build script.

```sh
cargo add procage
```

```rust
use procage::native::{Cage, Grants};
use procage::policy::{AbsPath, presets};

let workspace = AbsPath::new("/Users/me/project")?;
let cage = Cage::new(&presets::agent_readonly::v3(&workspace))?;
let status = cage
    .spawn(&mut std::process::Command::new("make"), &Grants::new())?
    .wait()?;
```

๐Ÿ“– [Documentation](https://hupe1980.github.io/procage) ยท
๐Ÿ” [Threat model](crates/procage/THREAT_MODEL.md) ยท
๐Ÿ“ [Design records](specs/README.md) ยท
๐Ÿ“ [Changelog](CHANGELOG.md) ยท
๐Ÿšจ [Report an escape](SECURITY.md)

> ๐Ÿšง **Pre-1.0.** The API may change between minor versions. Read the
> [threat model]crates/procage/THREAT_MODEL.md for what procage contains
> and where it stops.

## โœจ Features

- ๐Ÿงฉ **One typed policy, lowered per OS.** Anything a host cannot enforce is
  a named capability gap, never a weaker rule. `Cage::fit` relaxes only what
  you name and says what would lift each relaxation.
- ๐Ÿ”’ **A hard-deny tier in every policy.** Secrets, git hooks, shell startup
  files, launch agents, your service manager and container engines are
  denied last and waivable only by name.
- ๐Ÿงน **Hygiene and lifetime.** Inherited descriptors are closed,
  secret-looking variables dropped, and every process a run started is
  killed when it ends, double-forked daemons included.
- ๐Ÿงญ **Explain and diff.** `Cage::explain` names the rule that allows or
  denies reading, writing or executing a path and the narrowest change
  that would allow it; `explain::diff` shows what a policy change allows.
  The kernel checks every answer on every CI lane.
- ๐Ÿงพ **Receipts.** Every finished run says how it was caged: policy digest,
  backend and tier, and everything accepted short of the policy.
- ๐Ÿ”Ž **Violation reports.** A cage can say what the sandbox denied and which
  rule denied it: every denial on macOS, every refused system call on Linux.
- ๐ŸŒ **Egress through an allowlist.** With the `proxy` feature, a run
  reaches the hosts an allowlist names through a proxy of its own, and no
  other route (macOS, Linux T1). One canonical host parser, checked
  resolution, no allow-all.
- โšก **Async (tokio).** With the `tokio` feature, `Cage::spawn_async`
  returns an awaitable child, and violations arrive as a stream.
- ๐Ÿ“ฆ **Frozen presets and base profiles** that let ordinary programs and
  developer tools start, and `Cage::exec` and `Cage::exec_session` for
  helpers that become the caged command.

## ๐Ÿ–ฅ๏ธ Platforms

| Platform | Mechanism | Needs |
|---|---|---|
| ๐ŸŽ macOS | Seatbelt, applied through libsandbox | A caller that is not itself sandboxed |
| ๐Ÿง Linux T1 | Namespaces, mounts, Landlock, seccomp | Unprivileged user namespaces, Landlock ABI 1 (Linux 5.13) |
| ๐Ÿง Linux T2 | Landlock, seccomp | Landlock ABI 1 (Linux 5.13), e.g. Docker's defaults |

procage picks the strongest tier the host allows and never runs a child
unsandboxed.

**Known limits:** no pseudo-terminals, no Linux PID namespace, no loopback
networking on Linux and no proxy-only networking on tier T2, and Landlock's
file and network denials are not reported.

## โฑ๏ธ Performance

Median overhead of a caged spawn over a plain one (`just bench`):

| Host | procage, cached cage | Comparison |
|---|---|---|
| Apple M4 Pro, macOS 26.6.2 | 1.0 ms | `sandbox-exec -p`: 10.9 ms |
| Linux 7.0 aarch64 (Docker) | T1 1.0 ms, T2 0.27 ms | `bwrap`: 1.4 ms |

On macOS a new policy costs 11.6 ms once, to compile its profile.
Details: [benchmarks](https://hupe1980.github.io/procage/docs/testing/#benchmarks).

## ๐ŸŽฏ Threat model

procage contains adaptive code running as your user inside the child, and
keeps it away from your secrets, files outside the granted paths, your
terminal and session, and persistence locations. An OS sandbox reduces this
risk but does not remove it: kernel and OS service bugs are out of scope, so
use a microVM where such an escape is unacceptable.

The [threat model](crates/procage/THREAT_MODEL.md) lists every known escape
class and its status. A class counts as handled only when caged canaries on
a real kernel show the refusal. Every change is specified,
threat-modelled and verified in the open: see the
[design records](specs/README.md).

## ๐Ÿ› ๏ธ Development

```sh
just ci            # every local gate: fmt, lints, tests, docs, deny, MSRV (1.99), no_std, semver
just escape        # the macOS escape suite
just linux-t1      # the Linux tests in Docker, tier T1 (`just linux` for T2)
just kernel        # the Linux suites on mainline kernels, one per Landlock ABI step
just test-outside  # the kernel facts, from a terminal outside any sandbox
```

The kernel facts (`crates/procage-kernel-facts`) re-verify on the running
kernel the OS behaviour procage relies on. Facts that apply a sandbox fail
rather than skip inside another Seatbelt sandbox, such as an AI agent's.

## ๐Ÿ“„ License

Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
[MIT license](LICENSE-MIT) at your option.