Skip to main content

Official Python SDK for Rustbox - run untrusted code in a kernel-enforced sandbox.

Project description

🐍 Rustbox Python SDK

PyPI version Python

Async-first via httpx. One required dep. Typed exceptions.

⚠️ Async-only. All public methods are coroutines. Wrap with asyncio.run() from sync code.

🚀 Install

pip install rustbox        # or: uv pip install rustbox / poetry add rustbox

⚡ Quickstart

import asyncio, os
from rustbox import Rustbox

async def main():
    client = Rustbox(os.environ["RUSTBOX_API_KEY"])
    result = await client.run(language="python", code="print('hello')")
    print(result["verdict"], result["stdout"])  # AC hello

asyncio.run(main())

run() submits, waits for sync completion, polls if needed, returns the verdict.

Profiles

# Judge profile (default) - short evaluation runs, no egress proxy.
await client.run("python", "print(1)")

# Agent profile - longer jobs, egress proxy on, per-key byte budget.
# Requires a non-trial API key.
await client.run("python", "...", profile="agent")

🔒 Errors

from rustbox import (
    RustboxAuthError, RustboxRateLimitError, RustboxServerError, RustboxError,
)

try:
    await client.run("python", "...")
except RustboxAuthError:       pass  # 401/403
except RustboxRateLimitError:  pass  # 429 - back off
except RustboxServerError:     pass  # 5xx - retry
except RustboxError:           pass  # other
🧰 Full API
Rustbox(
    api_key: str,
    base_url: str = DEFAULT_BASE_URL,
    *,
    timeout_secs: float = 65.0,
    max_retries: int = 2,
)

await client.run(
    language: str,
    code: str,
    stdin: str = "",
    profile: Literal["judge", "agent"] | None = None,
)  # -> dict

await client.submit(
    language, code, stdin="",
    profile=None, wait=False,
    idempotency_key=None,
    webhook_url=None,
    webhook_secret=None,
)  # -> dict

await client.get_result(job_id)    # -> dict
await client.get_languages()       # -> list[str]
await client.get_health()          # -> dict
await client.get_ready()           # -> dict
await client.aclose()              # close httpx connection pool
🧪 Tests
cd sdk/python
uv pip install pytest pytest-asyncio respx httpx
python -m pytest -q

respx mocks httpx. No network.

🔗

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rustbox-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rustbox-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file rustbox-0.1.0.tar.gz.

File metadata

  • Download URL: rustbox-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for rustbox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 94b2a4d10d826bcbc5c52667e5195f519e6212bcdb96f4bbdb2ad9eb9d056ef8
MD5 52483942af307ae4bce63f92610dcafe
BLAKE2b-256 6cce3969330a9899c3bc475ec0495810108bc4d29d9df8adacbdb08bc8c54687

See more details on using hashes here.

File details

Details for the file rustbox-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rustbox-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for rustbox-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c67251610dc9b23374fbc7796bbf1f2717777ae830563440accd305ea4757d0
MD5 12b77fdd1e8d34b3827559135ba9f54e
BLAKE2b-256 7c7c03462ebbe70e6827ec719f6d3fb537a0168ae82d77d36f585c524e1d39dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page