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

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.6.1
File Interpreter ABI Platform Actions
procage-0.6.1-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details for procage-0.6.1-cp311-abi3-manylinux_2_28_x86_64.whl
procage-0.6.1-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details for procage-0.6.1-cp311-abi3-manylinux_2_28_aarch64.whl
procage-0.6.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for procage-0.6.1-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 2.5 MB

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

Download URL procage-0.6.1-cp311-abi3-manylinux_2_28_x86_64.whl
Size 915.9 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
d8218f3773bfd188bf8564eebed0be5709c04e44e567a5cf423c66e229d3fa11
BLAKE2b-256 checksum
How to use checksums
a557a546a192577f19a12fdb514e67241a4ebec28ccd01951242c24b818bb5cd
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 log

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

Download URL procage-0.6.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
66f73b8571040ff70cd98a0085e0f487e8436beb1ddb078e31b910399a063811
BLAKE2b-256 checksum
How to use checksums
d0ab3480817f5c047d41e71430d0840bf141aae31d8262ffaecc012207e70685
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 log

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

Download URL procage-0.6.1-cp311-abi3-macosx_11_0_arm64.whl
Size 786.0 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
34599676ef2128371de0540eb72e3fd3792d336608ce289a01d7690a813ce131
BLAKE2b-256 checksum
How to use checksums
331624a8678e6bfa40e3153adc69201d5b797e4ad2a7baca4335da1bff09d049
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 log

Security for procage 0.6.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.

Select from 3 files

Attestation for procage-0.6.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 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