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

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

Total release size: 2.6 MB

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

Download URL procage-0.6.0-cp311-abi3-manylinux_2_28_x86_64.whl
Size 923.3 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
792415df06794ac8c8d885692c3d90ba8a2ad56f2e2001bd73061f50137a39f6
BLAKE2b-256 checksum
How to use checksums
c213208fab660b7401e1b0a8dbd70201d748a76eb39f869371f24706ad9ebc04
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.0-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL procage-0.6.0-cp311-abi3-manylinux_2_28_aarch64.whl
Size 854.7 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
86b7ca4efcd1188425887095699c8494f0d861f2f3254df432c3f3bdfc2524f6
BLAKE2b-256 checksum
How to use checksums
bf427f7597cc05a3c7b83ec7c213b90f109821810e15fa81ba485cf7a7f5a499
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.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL procage-0.6.0-cp311-abi3-macosx_11_0_arm64.whl
Size 793.5 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1fc6e6e005b664ecba176e418226529d5d6dce8842d93de871fb8e6c416d5f63
BLAKE2b-256 checksum
How to use checksums
a6f4124ed2029be255a5d1c68c99a00a580e913ae38f889e2f72c8017d02f96d
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.0

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