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.
Metadata
Release files for ai2in 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai2in-0.3.0.tar.gz | 8.2 kB | With provenance | Details for ai2in-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai2in-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for ai2in-0.3.0-py3-none-any.whl |
Total release size: 17.5 kB
Release files / ai2in-0.3.0.tar.gz
| Download URL | ai2in-0.3.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa0c0a77be9e00a7321b4992b6d643aec389c366d499b2339d13443f9743e29e
|
|
BLAKE2b-256 checksum How to use checksums |
9f988c9a492ea9d4b852c79fae049cd20e19924b0a111b0b5b80b55ba8737fb6
|
| 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 Jul 4, 2026.
Transparency logRelease files / ai2in-0.3.0-py3-none-any.whl
| Download URL | ai2in-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b509c128e702f6f5105d7185382189ac6a65d39f74111a639d6c39d20569a7f1
|
|
BLAKE2b-256 checksum How to use checksums |
c7b7848c1108f7c2b412d4e3b113b7d5b4b8d2a89332e876d28ad281a0086620
|
| 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 Jul 4, 2026.
Transparency logSecurity for ai2in 0.3.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.
Attestation for ai2in-0.3.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 Jul 4, 2026.
Transparency logA 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.