Skip to main content

caged

Official Python SDK for the Caged AI Agent Sandbox Platform.

PyPI Python

Installation

pip install caged-sdk

Quick Start

from caged import Caged

caged = Caged(api_key="caged_sk_...")

# Create a sandbox
sandbox = caged.sandboxes.create(template="node-20", memory_mb=1024)
print(f"Sandbox {sandbox.id} is {sandbox.status}")

# Run a command
result = caged.sandboxes.exec(sandbox.id, "echo 'hello world'")
print(result.output)

# Write and read files
caged.files.write(sandbox.id, "/workspace/hello.py", "print('hi')")
content = caged.files.read(sandbox.id, "/workspace/hello.py")

# Create a snapshot
snapshot = caged.snapshots.create(sandbox.id, name="checkpoint-1")

# Clean up
caged.sandboxes.destroy(sandbox.id)

Context Manager

with Caged(api_key="caged_sk_...") as caged:
    sandbox = caged.sandboxes.create(template="python-312")
    result = caged.sandboxes.exec(sandbox.id, "python --version")
    print(result.output)
    caged.sandboxes.destroy(sandbox.id)

Interactive Terminal (WebSocket)

import asyncio
from caged import Caged

async def main():
    caged = Caged(api_key="caged_sk_...")
    sandbox = caged.sandboxes.create(template="node-20")

    terminal = await caged.sandboxes.terminal(sandbox.id)
    terminal.on_output(lambda data: print(data, end=""))
    await terminal.send("ls -la\n")
    await asyncio.sleep(2)
    await terminal.close()

asyncio.run(main())

Streaming Exec

import asyncio
from caged import Caged

async def main():
    caged = Caged(api_key="caged_sk_...")
    sandbox = caged.sandboxes.create(template="node-20")

    stream = await caged.sandboxes.exec_stream(sandbox.id, "npm test")
    async for chunk in stream:
        print(chunk, end="")
    print(f"\nExit code: {stream.exit_code}")

asyncio.run(main())

MCP (Model Context Protocol)

import asyncio
from caged import Caged

async def main():
    caged = Caged(api_key="caged_sk_...")
    sandbox = caged.sandboxes.create(template="node-20")

    mcp = await caged.sandboxes.mcp(sandbox.id)

    # List available tools
    tools = await mcp.list_tools()
    for tool in tools:
        print(f"  {tool.name}: {tool.description}")

    # Call a tool
    result = await mcp.call_tool("terminal_exec", {"command": "npm test"})
    print(result["content"][0]["text"])

    await mcp.close()

asyncio.run(main())

Session Replay

caged = Caged(api_key="caged_sk_...")

# List sessions for a sandbox
sessions = caged.sessions.list_by_sandbox("sandbox-id")
for s in sessions:
    print(f"{s.id}: {s.agent_type} — ${s.cost_usd:.4f}")

# Get replay timeline
events = caged.sessions.replay(sessions[0].id)
for event in events:
    print(f"[{event.timestamp}] {event.type}: {event.data}")

# Get summary
summary = caged.sessions.replay_summary(sessions[0].id)
print(f"Duration: {summary.duration_ms}ms, Cost: ${summary.cost_usd:.4f}")

Events Ingestion

from caged import Caged, EventPayload

caged = Caged(api_key="caged_sk_...")

response = caged.events.ingest([
    EventPayload(
        type="llm_call",
        sandbox_id="sandbox-id",
        data={"model": "claude-4", "tokens_in": 500, "tokens_out": 200},
    ),
])
print(f"Accepted: {response.accepted}, Errors: {response.errors}")

Alerts & Notifications

caged = Caged(api_key="caged_sk_...")

# List alerts
alerts = caged.alerts.list()
for alert in alerts:
    print(f"[{alert.severity}] {alert.message}")

# Resolve an alert
caged.alerts.resolve(alerts[0].id)

# Check notifications
count = caged.notifications.unread_count()
print(f"Unread: {count}")

notifications = caged.notifications.list()
caged.notifications.mark_all_read()

Billing

caged = Caged(api_key="caged_sk_...")

sub = caged.billing.get_subscription()
print(f"Plan: {sub.plan}, Status: {sub.status}")

# Get checkout URL for upgrade
url = caged.billing.create_checkout("pro")
print(f"Upgrade: {url}")

Full API Reference

Sandboxes

Method Description
sandboxes.create(template, cpus, memory_mb, ...) Create a sandbox
sandboxes.list() List all sandboxes
sandboxes.get(id) Get sandbox by ID
sandboxes.destroy(id) Destroy a sandbox
sandboxes.exec(id, command) Run a command (sync)
await sandboxes.exec_stream(id, command) Stream command output (async)
await sandboxes.terminal(id) Interactive terminal (async)
await sandboxes.mcp(id) MCP tool client (async)
sandboxes.pause(id) Pause a sandbox
sandboxes.resume(id) Resume a paused sandbox
sandboxes.logs(id, tail=N) Get sandbox logs
sandboxes.ports(id) List open ports
sandboxes.trust_scores(sandbox_id) Get trust scores

Files

Method Description
files.list(sandbox_id, path) List directory contents
files.read(sandbox_id, path) Read file content
files.write(sandbox_id, path, content) Write file content
files.git_diff(sandbox_id) Get git diff

Snapshots

Method Description
snapshots.list(sandbox_id) List snapshots
snapshots.create(sandbox_id, name, description) Create snapshot
snapshots.get(snapshot_id) Get snapshot details
snapshots.delete(snapshot_id) Delete snapshot
snapshots.download_url(snapshot_id) Get download URL
snapshots.restore(snapshot_id) Restore snapshot

Sessions (Agent history & replay)

Method Description
sessions.list_by_sandbox(sandbox_id) List agent sessions
sessions.get(session_id) Get session details
sessions.replay(session_id) Get replay timeline
sessions.replay_summary(session_id) Get replay summary

Events

Method Description
events.ingest(events) Ingest observability events

Alerts

Method Description
alerts.list() List all alerts
alerts.get(id) Get alert by ID
alerts.resolve(id) Resolve an alert
alerts.list_rules() List alert rules
alerts.update_rule(id, **kwargs) Update alert rule

Notifications

Method Description
notifications.list() List notifications
notifications.unread_count() Get unread count
notifications.mark_read(id) Mark as read
notifications.mark_all_read() Mark all as read
notifications.get_config() Get notification config
notifications.update_config(**kwargs) Update config

Account

Method Description
account.list_keys() List API keys
account.create_key(name) Create new API key
account.revoke_key(id) Revoke an API key
account.list_sessions() List active sessions
account.revoke_session(id) Revoke a session

Billing

Method Description
billing.get_subscription() Get subscription details
billing.create_checkout(plan) Get Stripe checkout URL
billing.create_portal() Get billing portal URL
billing.cancel() Cancel subscription

Error Handling

from caged import Caged, CagedAPIError, CagedTimeoutError

caged = Caged(api_key="caged_sk_...")

try:
    caged.sandboxes.get("nonexistent")
except CagedAPIError as e:
    print(f"API error {e.status}: {e}")
except CagedTimeoutError as e:
    print(f"Timeout: {e}")

License

MIT

Metadata

Release files for caged-sdk 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 caged-sdk 0.2.0
File Size Uploaded Provenance Actions
caged_sdk-0.2.0.tar.gz 13.0 kB With provenance Details for caged_sdk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for caged-sdk 0.2.0
File Interpreter ABI Platform Actions
caged_sdk-0.2.0-py3-none-any.whl Python 3 none any Details for caged_sdk-0.2.0-py3-none-any.whl

Total release size: 29.3 kB

Release files / caged_sdk-0.2.0.tar.gz

Download URL caged_sdk-0.2.0.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ab0f8b34a8bca8768be32d27f0aa9fabed614f833353de99591830b7f9f1021b
BLAKE2b-256 checksum
How to use checksums
9a00d9e6e67f5e91c9656e4e82f0b7a0dce050f9367bec5096581f42a5e43802
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 14, 2026.

Transparency log

Release files / caged_sdk-0.2.0-py3-none-any.whl

Download URL caged_sdk-0.2.0-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68afe0572a56cd425896cadf9144379c3f8de08e02e61aa2625ad056b9b38f1b
BLAKE2b-256 checksum
How to use checksums
dbf7d913ffe986390e3beb8d7a4a44d0df34bc069433813962d4584e61b8b442
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 14, 2026.

Transparency log

Security for caged-sdk 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for caged_sdk-0.2.0.tar.gz

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 Jun 14, 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full 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