Skip to main content

Iron Cage

Python License

Python SDK for Iron Cage AI agent protection. Provides LlmRouter and Runtime for protecting AI agents with budget tracking, safety controls, and LLM API proxying.

Installation

uv pip install iron-cage

Quick Start

from iron_cage import LlmRouter
from openai import OpenAI

# Use with Iron Cage server
with LlmRouter(api_key="ic_xxx", server_url="https://api.iron-cage.io") as router:
    client = OpenAI(base_url=router.base_url, api_key=router.api_key)
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(response.choices[0].message.content)

# Or with direct provider key (for testing)
with LlmRouter(provider_key="sk-xxx", budget=10.0) as router:
    client = OpenAI(base_url=router.base_url, api_key=router.api_key)
    # ... use client

Architecture

Iron Cage Architecture - Three-Boundary Model

Iron Cage uses a two-crate architecture:

Crate Language Purpose
iron_runtime Pure Rust Core implementation - LlmRouter, AgentRuntime, policies
iron_sdk (folder) Rust + Python PyO3 bindings exposing iron_runtime to Python

Package Hierarchy:

What you install:  uv pip install iron-cage
What you import:   from iron_cage import LlmRouter, Runtime
Internal:          iron_runtime (Rust crate, linked at compile time)

Key Features

  • LLM Proxy: Local HTTP proxy that intercepts OpenAI/Anthropic API requests
  • Budget Control: Set and track spending limits in USD
  • Auto-detection: Automatically detects provider from API key format
  • Context Manager: Clean resource management with with statement
  • Type Stubs: Full IDE support with .pyi files

API Reference

LlmRouter

LlmRouter(
    api_key: str = None,           # Iron Cage API token
    server_url: str = None,        # Iron Cage server URL
    cache_ttl_seconds: int = 300,  # API key cache TTL
    budget: float = None,          # Budget limit in USD
    provider_key: str = None,      # Direct provider API key
)

Properties:

  • base_url - URL for OpenAI client (e.g., "http://127.0.0.1:52431/v1")
  • api_key - API key to use with client
  • port - Port the proxy is listening on
  • provider - Detected provider ("openai" or "anthropic")
  • is_running - Whether proxy is running
  • budget - Current budget limit in USD
  • budget_status - Tuple of (spent, limit) in USD

Methods:

  • total_spent() - Get total spent in USD
  • set_budget(amount_usd) - Set budget limit
  • stop() - Stop the proxy server

Runtime

Runtime(
    budget: float,           # Budget limit in USD
    verbose: bool = False,   # Enable verbose logging
)

Properties:

  • budget - Budget limit
  • verbose - Verbose setting

Methods:

  • start_agent(script_path) - Start an agent
  • stop_agent(agent_id) - Stop an agent
  • get_metrics(agent_id) - Get agent metrics as JSON
Optional Dependencies
# LangChain integration
uv pip install iron-cage[langchain]

# CrewAI integration
uv pip install iron-cage[crewai]

# All integrations
uv pip install iron-cage[all]

# Examples dependencies
uv pip install iron-cage[examples]
Examples

See examples/ directory for runnable examples:

  • examples/langchain/ - LangChain integration examples
  • examples/crewai/ - CrewAI integration examples
  • examples/raw_api/ - Direct API usage examples
  • examples/patterns/ - Protection pattern examples

Run examples:

python examples/lead_gen_agent.py

Development

# Build the Python package
cd module/iron_sdk
maturin develop

# Run tests
pytest tests/

Documentation

  • Specification: See spec.md for complete technical requirements
  • Examples: See examples/ directory

License

Apache-2.0 - See license file for details

Metadata

Release files for iron-cage 0.2.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 iron-cage 0.2.0
File Size Uploaded Provenance Actions
iron_cage-0.2.0.tar.gz 170.6 kB Without provenance Details for iron_cage-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for iron-cage 0.2.0
File Interpreter ABI Platform Actions
iron_cage-0.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for iron_cage-0.2.0-cp312-cp312-win_amd64.whl
iron_cage-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details for iron_cage-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
iron_cage-0.2.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for iron_cage-0.2.0-cp312-cp312-macosx_11_0_arm64.whl

Total release size: 13.2 MB

Release files / iron_cage-0.2.0.tar.gz

Download URL iron_cage-0.2.0.tar.gz
Size 170.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0364ac71a0046e130e1a3003fd4ec12e2679f505dcae0eca99bd1a078ca68a1e
BLAKE2b-256 checksum
How to use checksums
f22efb3b2b149cce3e55f9d4db616c43478453df3e9ba4087393d751001a1f11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iron_cage-0.2.0-cp312-cp312-win_amd64.whl

Download URL iron_cage-0.2.0-cp312-cp312-win_amd64.whl
Size 3.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
7e9bb6b7ccd646ec4724008b1cbea75c1b2a9ec05ec6c439dbc6741627dded2a
BLAKE2b-256 checksum
How to use checksums
3c95a1d7ac2fd0e59113f4a885b5a29448dc0e6b4d7c436cedb6a14ee84b0577
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iron_cage-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL iron_cage-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Size 6.8 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
08d46ce57d2c534734b9de909ecea603a9fff8884d47c0de2bb4d740a1cc8a0f
BLAKE2b-256 checksum
How to use checksums
7bc55fbd0ab19d176bcfdbd9c4814b2b056e24fe32f14915a82650d43974596f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.3

Release files / iron_cage-0.2.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL iron_cage-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Size 3.2 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e793a789cb35d3075f98cc68a9ba769b2d830650a187e0d2cbbc5e087cb0911f
BLAKE2b-256 checksum
How to use checksums
2141986e864a0adb697faf6e3988d79ff3b98e208dfba5e1b4e2c516d81f28ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.10.2

Security for iron-cage 0.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

4 release files No provenance

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