Skip to main content

Python SDK for AI2IN — secure AI code sandboxes, hosted in India.

Project description

ai2in — Python SDK

The developer client for AI2IN.dev — secure AI code sandboxes, hosted in India. Spin up an isolated Linux sandbox, run untrusted / AI‑generated Python in a stateful kernel, and get back rich, typed results (text, HTML tables, charts, JSON) — the E2B code‑interpreter model, in‑region.

Stdlib‑only, zero dependencies.

Install

pip install ai2in            # once published
# or, from this repo:
pip install -e sdk/python

Quickstart

from ai2in import Sandbox

with Sandbox(api_key="ai2in_live_…", base_url="https://api.ai2in.dev") as sbx:
    execution = sbx.run_code(
        "import pandas as pd; pd.DataFrame({'gst_lakh_cr': [1.87, 1.73, 1.95]})"
    )

    print(execution.text)            # the main result's plain text
    print(execution.logs.stdout)     # ['…']

    for r in execution.results:      # rich, typed outputs
        if r.html:                   # e.g. a DataFrame → HTML table
            save(r.html)
        if r.png:                    # e.g. a matplotlib figure → base64 PNG
            save_image(r.png)

    if execution.error:              # structured error for self-correction
        print(execution.error.name, execution.error.value)

State persists across run_code calls in the same sandbox (like a notebook):

sbx.run_code("x = 41")
sbx.run_code("x + 1").text   # "42"

Streaming

Pass callbacks to stream output live as the kernel produces it (long loops, training logs, incremental prints). The events are still accumulated into the returned Execution, so the return value is identical whether or not you stream:

execution = sbx.run_code(
    "for i in range(5):\n    print('step', i)\n    import time; time.sleep(1)",
    on_stdout=lambda t: print(t, end="", flush=True),  # arrives chunk-by-chunk
    on_result=lambda r: render(r),                     # display() calls, figures, the value
    on_error=lambda e: print(e.value),
)
print(execution.execution_ms)                          # still get the full Execution

Result model

run_code() returns an Execution:

Field Type Notes
results list[Result] rich outputs; the cell's value has is_main_result=True
logs Logs .stdout / .stderr (lists of str)
error ExecutionError | None .name, .value, .traceback
text str | None convenience: the main result's text

Each Result may carry any of: text, html, markdown, svg, png, jpeg, pdf, latex, json, javascript. Call r.formats() for what's present.

Local dev

Point at a local engine (default http://localhost:4000):

with Sandbox() as sbx:            # talks to localhost:4000
    print(sbx.run_code("print(1 + 1)").logs.stdout)

© 2026 AI2IN.dev — see the repository LICENSE.

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

ai2in-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

ai2in-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai2in-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ai2in-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d6c7bc0dc3b58986633623395b787762145ce1f185c7dc880dfc00c5ef734e93
MD5 49a32913953f16430610dbd10ea5cd46
BLAKE2b-256 7d4f16e503a1ea2871352083b6383a604d80eadb631d8a3beca0c17ba51ae1da

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai2in-0.1.0.tar.gz:

Publisher: publish.yml on AI2IN-DEV/AI2IN

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: ai2in-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ai2in-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 725b1abc01dcb964c4fafce47f17d418b986501d9ba7f3fc31e9acd68000ee50
MD5 f5107fbda3df4b4a2c1801895e2aa43e
BLAKE2b-256 c87a7fbf1972f12c8bb438d95ef890a37f1671f2b5118f84851cfa5038913031

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai2in-0.1.0-py3-none-any.whl:

Publisher: publish.yml on AI2IN-DEV/AI2IN

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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