procage
Run commands caged by the operating system's sandbox, from Python. On macOS
procage applies Seatbelt profiles through libsandbox (no sandbox-exec); on
Linux it uses Landlock, seccomp and, where the host allows, user namespaces.
This package binds the Rust crate procage:
the same presets, the same checks, the same refusals.
pip install procage
Wheels: macOS on Apple silicon, Linux x86_64 and aarch64 (manylinux_2_28), CPython 3.11 and later. Every wheel platform runs the binding's escape tests in CI.
import procage
policy = procage.Policy.preset("agent_workspace", 3, workspace="/abs/project")
done = procage.run(policy, "make test", shell=True, text=True, timeout=600)
print(done.returncode, done.stdout)
A preset's runs start in its workspace unless cwd= says otherwise.
procage.run reads like subprocess.run: text=, check= (raises
subprocess.CalledProcessError), shell=, input=, timeout=; paths may
be pathlib.Path.
agent_workspace lets the command read and write the workspace, run the
system's programs and nothing else: no network, no secrets of the user's
home, no writes outside the workspace. Other presets: minimal,
agent_readonly, build (adds loopback networking; macOS only). Any
policy can also be loaded from procage's versioned JSON format with
Policy.from_json.
Runs
cage = procage.Cage(policy, violations=True) # reuse for many runs
with cage.spawn(["python3", "tool.py"], env={"MODE": "ci"}) as run:
out, err = run.communicate(timeout=60)
print(run.returncode, run.violations())
- Only the variables in
env=are set explicitly; the policy decides which of your process's variables reach the child.os.environis never copied. stdin,stdoutandstderrare"pipe","null"(stdin's default) or"inherit".Run.poll(),wait(timeout),await wait_async(),communicate(),kill(),violations()andreceipt(). Blocking calls release the interpreter lock.- A run ends, and every process it started is killed, when the
Runis closed, garbage-collected, or the interpreter exits.
When the host cannot enforce part of a policy, Cage raises
CapabilityGapError, and its message names the option that would accept
each gap, for example on Linux:
hd-secrets: Cage(..., accept_spawn_snapshot=True) accepts it
hd-trust-handoff: Cage(..., relax=["waive:trust-handoff"]) accepts it
Nothing is accepted unless you pass it.
asyncio
done = await procage.run_async(policy, "pytest -q", shell=True, text=True)
run_async, Run.communicate_async and Run.wait_async take the same
arguments as their blocking twins; the waiting happens on worker threads,
so many runs proceed at once. Cancelling the awaiting task ends the run:
a cancelled tool call leaves no caged process behind.
Errors
procage.Error and its subclasses PolicyError, CapabilityGapError
(.gaps lists what the host cannot enforce), UnsupportedError,
AlreadySandboxedError (the caller is itself sandboxed, macOS),
GrantError and SpawnError.
An agent's shell tool
examples/shell_tool.py
is one function, shell(command, workspace), that any agent framework can
register as a tool: it runs the command caged and returns the exit code,
the output and what the sandbox refused.
Documentation: https://hupe1980.github.io/procage/docs/python/. Read the threat model for what an OS sandbox does and does not stop.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Metadata
Release files for procage 0.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| procage-0.7.1-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details for procage-0.7.1-cp311-abi3-manylinux_2_28_x86_64.whl |
| procage-0.7.1-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details for procage-0.7.1-cp311-abi3-manylinux_2_28_aarch64.whl |
| procage-0.7.1-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for procage-0.7.1-cp311-abi3-macosx_11_0_arm64.whl |
Total release size: 2.5 MB
Release files / procage-0.7.1-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | procage-0.7.1-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 916.4 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
dfb2eff6626409ae12f65bfea147afdfa163e95b84ceacf4c16486e47a921d53
|
|
BLAKE2b-256 checksum How to use checksums |
e371d94aabc273fbbfdf90792fe602264147a69b2335483eb2d13f8f9ab55f01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / procage-0.7.1-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | procage-0.7.1-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 847.3 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
a92e6420d6636e328a051e11d8ed38ef44d504373e2f409bf5ec0fbd42886fe8
|
|
BLAKE2b-256 checksum How to use checksums |
8dc21436bce28cbd66b3c9a6ff05d4e3fd10badece185a1aed4d811962a78a2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / procage-0.7.1-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | procage-0.7.1-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 785.9 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0cce9627948a91769e6b74267eee82fdec95df8e499c363bdc24c26e2c488bf3
|
|
BLAKE2b-256 checksum How to use checksums |
0e1caab0947e18920a0dc5db8cfbd7a1ff6afcff7490c9ebbef77ea444bd6b6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logSecurity for procage 0.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 3 files in this release have been uploaded with provenance metadata.
Attestation for procage-0.7.1-cp311-abi3-manylinux_2_28_x86_64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.