Skip to main content

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.environ is never copied.
  • stdin, stdout and stderr are "pipe", "null" (stdin's default) or "inherit".
  • Run.poll(), wait(timeout), await wait_async(), communicate(), kill(), violations() and receipt(). Blocking calls release the interpreter lock.
  • A run ends, and every process it started is killed, when the Run is 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.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for procage 0.7.2
File Interpreter ABI Platform Actions
procage-0.7.2-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details for procage-0.7.2-cp311-abi3-manylinux_2_28_x86_64.whl
procage-0.7.2-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details for procage-0.7.2-cp311-abi3-manylinux_2_28_aarch64.whl
procage-0.7.2-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for procage-0.7.2-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 2.6 MB

Release files / procage-0.7.2-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL procage-0.7.2-cp311-abi3-manylinux_2_28_x86_64.whl
Size 917.5 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
8caef82cc65769e875e21e2172c58f9990cfe5d8b6e1cc8a5eecd3ab1a498ed0
BLAKE2b-256 checksum
How to use checksums
5921855d27e697d88250fb9133748d4f7f1d3183232a4a842e8cd08e2ea97f93
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 11, 2026.

Transparency log

Release files / procage-0.7.2-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL procage-0.7.2-cp311-abi3-manylinux_2_28_aarch64.whl
Size 847.8 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
7b2ed63301c48bf94cdf52505948c189e88a85efa5d6d9323482c9d73c8f86d9
BLAKE2b-256 checksum
How to use checksums
a3f56f39fa9f2ff98419cfb938a678b5487a84443c3134908a52bf882b09bbcb
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 11, 2026.

Transparency log

Release files / procage-0.7.2-cp311-abi3-macosx_11_0_arm64.whl

Download URL procage-0.7.2-cp311-abi3-macosx_11_0_arm64.whl
Size 788.5 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
400882f48b0aae53806b6e2921fdd6c2e74e49a6f36f86495bfef0df67885319
BLAKE2b-256 checksum
How to use checksums
f3f2a7e3038cc5075b4b0b4ed30b4f9e20f22ea6fd4f87937964f1a3e10888aa
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 11, 2026.

Transparency log

Security for procage 0.7.2

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.

Select from 3 files

Attestation for procage-0.7.2-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 11, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page