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.3.0.tar.gz (8.2 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.3.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ai2in-0.3.0.tar.gz
Algorithm Hash digest
SHA256 fa0c0a77be9e00a7321b4992b6d643aec389c366d499b2339d13443f9743e29e
MD5 d1d0add19e7195204f37241747842c0d
BLAKE2b-256 9f988c9a492ea9d4b852c79fae049cd20e19924b0a111b0b5b80b55ba8737fb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai2in-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: ai2in-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b509c128e702f6f5105d7185382189ac6a65d39f74111a639d6c39d20569a7f1
MD5 6eff1001fe7493f823c69df7bb4762ac
BLAKE2b-256 c7b7848c1108f7c2b412d4e3b113b7d5b4b8d2a89332e876d28ad281a0086620

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai2in-0.3.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