Skip to main content

Independent project: Cageforge is not affiliated with, sponsored by, or endorsed by OpenAI.

Cageforge Python binding

cageforge provides a typed Python API for the Cageforge sandbox on Linux, macOS, and Windows. It loads the selected profile and uses the native backend provided by the installed wheel.

The package is built with PyO3 and maturin. The published package name is cageforge.

Use the published cageforge crate as the project-level reference for the sandbox API. See the shared configuration guide for the complete Linux/macOS/Windows profile shape, including the resources a first restricted launch must declare separately from local IPC.

Install

python -m pip install cageforge

Each wheel contains the Python extension and the native resources for one operating-system and architecture target. Linux wheels include the pinned Bubblewrap resource. Applications do not need to install a separate native helper or provide a host-specific resource path.

The release also includes free-threaded CPython 3.14 wheels for each supported operating-system and architecture target. Standard CPython 3.10 and newer builds use the stable abi3 wheel for their platform.

Quick start with the repository smoke profile

The repository already contains one runnable profile for each supported OS. This example selects the profile for the current host and uses Cageforge.from_toml_file to run it. Run it from the repository root:

import platform
from pathlib import Path

from cageforge import Cageforge, PermissionApprover, RuntimeContext

platform_name = platform.system().lower()
profile_name = {
    "linux": "linux",
    "darwin": "macos",
    "windows": "windows",
}[platform_name]
profile = (
    Path("crates")
    / "cageforge-config"
    / "examples"
    / "runnable"
    / profile_name
    / "smoke.toml"
).resolve()

context = RuntimeContext(profile.parent)
toml = profile.read_bytes().decode("utf-8")
Cageforge.check_toml(toml, context=context)
request = Cageforge.permission_request(toml, context=context)
grant = PermissionApprover().approve(request)
with Cageforge.from_toml_file(
    profile, context=context, grant=grant, request=request
) as runtime:
    with runtime.launch() as process:
        print(process.read_stdout(4096).decode().strip())
        assert process.wait().exit_code == 0

The three profiles are linux/smoke.toml, macos/smoke.toml, and windows/smoke.toml. They use the current Cageforge TOML schema, include minimal read access, declare a workspace root, allow writes to workspace-root, and disable the network. The Windows profile uses cmd.exe; the POSIX profiles use /bin/echo.

Profiles with approval.mode = "preflight" require a trusted host grant before launch. PermissionRequest is descriptive; only PermissionApprover can issue the opaque PermissionGrant. A grant never changes an already-running process. When permission_request is called with custom identity or digest arguments, pass that same PermissionRequest to from_toml or from_toml_file; the runtime then authorizes the grant against the exact identity that was approved.

PermissionRequest.local_ipc() returns frozen typed LocalIpcEndpoint values. Their kind is unix_socket or windows_named_pipe, and value is the validated native endpoint. The platform overlay selects which endpoint kind is present; a Windows named-pipe request remains fail-closed if the native backend cannot prove the required isolation.

Persistent grants and store paths

The permission store is host state, not TOML policy. Choose its absolute path explicitly and use a persistent grant when the approval should survive a new process:

from pathlib import Path

from cageforge import PermissionApprover, PermissionStore

store = PermissionStore.open(Path("/var/lib/my-tool/permissions.json"))
toml = profile.read_bytes().decode("utf-8")
request = Cageforge.permission_request(toml, context=context)
grant = PermissionApprover().approve(request, scope="persistent")
store.put(grant, request)

cached = store.get(request)
assert cached is not None
with Cageforge.from_toml_file(
    profile, context=context, grant=cached, request=request
) as runtime:
    ...

PermissionStore protects the file with owner-only permissions on Unix and an owner-only DACL on Windows. It uses a versioned JSON document, a kernel file lock, and atomic replacement. A missing store record is not an approval; preflight remains deny-by-default.

Persistent grants can be inspected and revoked by stable ID without exposing their approved capability payload:

page = store.list_page(page_size=50)
for summary in page.entries:
    print(summary.id, summary.tool_id)
if page.next_cursor is not None:
    page = store.list_page(page_size=50, cursor=page.next_cursor)

result = store.revoke(request.grant_id())
assert str(result) in {"revoked", "not-found"}

GrantPageCursor is opaque and becomes stale when the store changes. The binding exposes stable store exception subclasses for invalid IDs, invalid cursors, page size, stale cursors, lock, read, write, and format failures. All digest and store validation is performed by the shared Rust implementation.

When profile_name is omitted, Cageforge.from_toml and check_toml use the TOML document's default_profile. Cageforge.from_toml_file reads a file and uses its parent directory as the default current directory. RuntimeContext() uses the Python process directory and lets the native adapter provide the platform's default minimal paths. Passing a path in RuntimeContext does not grant access unless the selected profile contains the corresponding rule.

The minimal selector is symbolic. Linux adapters supply the executable and loader paths needed by the selected backend, macOS supplies its system runtime paths, and Windows supplies the system root and System32 paths. Use the separate files under cageforge-config/examples/runnable/ when the command or path syntax is OS-specific. The macOS runtime.executable_roots overlay is passed through the same preflight request; its filesystem capabilities expose map-executable separately from read.

Profiles with approval.mode = "on-demand" may request additional access for a new sandbox launch. runtime.request_escalation(filesystem, network, reason) returns a structured request; the trusted host approves it with PermissionApprover.approve_escalation, and runtime.launch_escalated launches the approved immutable policy. The existing process is never widened in place and must be stopped by the host before relaunch. The same methods are available for preflight-and-on-demand. Unsupported or unrestricted additions raise CageforgeEscalationError.

Processes, asyncio, and errors

SandboxProcess provides try_wait, wait, wait_for, kill, and close, as well as read_stdout, read_stderr, write_stdin, and close_stdin. The wait_for method is a compatibility alias for wait. Blocking native waits and stream operations release the GIL.

For asyncio applications, wait_for_async(process) waits in a worker thread so the event loop remains responsive. Cancelling the coroutine terminates the process boundary and then propagates asyncio.CancelledError.

Configuration, initialization, launch, process, stream, and Windows setup failures use typed exceptions under CageforgeError, including CageforgeConfigurationError, CageforgeLaunchError, and CageforgeProcessError:

from cageforge import Cageforge, CageforgeConfigurationError

try:
    Cageforge.check_toml("not valid = [")
except CageforgeConfigurationError as error:
    print(f"invalid Cageforge configuration: {error}")

Windows setup and native resources

Windows provisioning is explicit because installation can require UAC. Before launching on Windows, an application can reconcile and verify the owner-scoped setup:

from cageforge import WindowsSetup

if WindowsSetup.is_supported():
    if WindowsSetup.status() != "ready":
        WindowsSetup.install()
    WindowsSetup.verify()

install() is the only operation in this sequence that may request elevation. Creating a runtime does not silently install Windows components. Linux wheels prefer a compatible system Bubblewrap and fall back to the bundled Bubblewrap resource shipped in the wheel. macOS uses the packaged native helper.

Development

From this directory, install maturin and the Python development tools, then use maturin develop, pytest, mypy --strict, and ruff check. The committed _cageforge.pyi stub is generated by running cargo run --bin stub_gen from this crate directory. The Java and Python bindings share the same native policy contract; binding-specific contract checks live with their respective tests.

Release files for cageforge 0.7.0

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

Source distribution (sdist)

Source distribution for cageforge 0.7.0
File Size Uploaded
cageforge-0.7.0.tar.gz 921.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for cageforge 0.7.0
File
cageforge-0.7.0-cp314-cp314t-win_arm64.whl CPython 3.14 CPython 3.14 free-threading Windows ARM64 Details
cageforge-0.7.0-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
cageforge-0.7.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Details
cageforge-0.7.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 Details
cageforge-0.7.0-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
cageforge-0.7.0-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details
cageforge-0.7.0-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
cageforge-0.7.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
cageforge-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
cageforge-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
cageforge-0.7.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
cageforge-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 85.9 MB

Release files / cageforge-0.7.0.tar.gz

Download URL cageforge-0.7.0.tar.gz
Size 921.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ae65f850571e59af8dcc481030f6347f149c736f2941166b31cd62a360cc9259
BLAKE2b-256 checksum
How to use checksums
e5f31ef7ae5363d3d643f7128e6577a91fddc9faaabb40ad28fc1ba39f07b505
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp314-cp314t-win_arm64.whl

Download URL cageforge-0.7.0-cp314-cp314t-win_arm64.whl
Size 7.0 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows ARM64
SHA-256 checksum
How to use checksums
9802ffa9ad1fbe886cb8f9c6663293444abd8fb4280188335510d7dc232ede9d
BLAKE2b-256 checksum
How to use checksums
d6a1cc4ef8632fcc56abf70cdd5950a233bb199c1af2ad00ae5aaa310a7fcb0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp314-cp314t-win_amd64.whl

Download URL cageforge-0.7.0-cp314-cp314t-win_amd64.whl
Size 7.4 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
c1f1e2dcfa544c5bf768cdd0a9f2a6738973a31da9204ff528020d98c1ab56b3
BLAKE2b-256 checksum
How to use checksums
2d083279edc8fdf1ef36cdd1924e99f5259726366e0af237783684a618bee418
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cageforge-0.7.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 7.5 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
249504c375777ff5f06ae1151f7170f6a66925c1f49c6350908d76bb33b6d756
BLAKE2b-256 checksum
How to use checksums
b5dbffc52374f52b5cb066076a47b2c6faa7ae9e8a13bd78be1a580b90ce0fc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL cageforge-0.7.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 7.4 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
c067f42305a129a39c3f5d5a04716612ca4ca428a4bc4c14cccc81baaddf947a
BLAKE2b-256 checksum
How to use checksums
bcd504cc67a520c6f8518250f59b7b3cec4bed9291f8f52319c483b9418c8937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp314-cp314t-macosx_11_0_arm64.whl

Download URL cageforge-0.7.0-cp314-cp314t-macosx_11_0_arm64.whl
Size 6.4 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
43ec3797e977d302c1d159a3db30914c62d17bf8448184bcd442a6d55384eb8e
BLAKE2b-256 checksum
How to use checksums
680587a022fb43c16c87736fe9a0c0372defbb723178da89f69b3073ae1d5db4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL cageforge-0.7.0-cp314-cp314t-macosx_10_12_x86_64.whl
Size 6.7 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
406174f1d67f2596c3732bacfcf0fb12fdc311072c099b24f828cb85edf09b25
BLAKE2b-256 checksum
How to use checksums
0545c84638d5c4b9bcefc0ff76b27ad895e36d7aea5e798b398a0646ee6e58b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp310-abi3-win_arm64.whl

Download URL cageforge-0.7.0-cp310-abi3-win_arm64.whl
Size 7.0 MB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
7892820d1f853c3d06b3a04b228d9b5630cb589427f6c5737068677560df2bf7
BLAKE2b-256 checksum
How to use checksums
af7452ce7df0a3d833f18d4b8a4ba2dd94b0213578f2707042cb25d892e413bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp310-abi3-win_amd64.whl

Download URL cageforge-0.7.0-cp310-abi3-win_amd64.whl
Size 7.5 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4d64c2f4cb69511b7d0c5e7e8e136aff95274567e40aee23ba27c2d08159abdd
BLAKE2b-256 checksum
How to use checksums
25e2bf9806788f5c700ed1c9f24225ad60beb4f234334730f9400087f660316a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cageforge-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 7.6 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
29ecfa2dbd1329f07f46a2a37703ffe15dfbf664e034c1724da2267321ce3b58
BLAKE2b-256 checksum
How to use checksums
4c39a86d670bf390099e0f12ee4d88410bc6d268715d3161162045dd9688e52c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL cageforge-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 7.4 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
44384ab0d47d55a5d97b39f16e4d08acd3d9e319d9235c7b01112090ee7c5ab0
BLAKE2b-256 checksum
How to use checksums
da32e2a1e441db6af147128ba624ae6be4d91e8df4ad5054076612e1dc289fc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL cageforge-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
Size 6.4 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
da3bc4723b03dea23bf1d3725e740cca131d23511ad5e469477ae8eb13e16aa1
BLAKE2b-256 checksum
How to use checksums
634e895f5f96cc9bc88723c412122234b5c0b6ab7df16cffa06588f8d2c5190f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release files / cageforge-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL cageforge-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 6.7 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d255cffe9a871dd9f21bd445fc626bf5aed4540bd7f671ae79edac5665be94db
BLAKE2b-256 checksum
How to use checksums
d3998ad3e6abc470831326707db0ee5586272318e27534ddd09bc694ee95cbce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

0.7.1

13 release files

This release

0.7.0 This release

13 release files

0.6.1

13 release files

0.6.0

13 release files

0.5.0

13 release files

0.4.0

13 release files

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