Metadata-Version: 2.5
Name: solari-e2b-compat
Version: 0.1.0
Summary: E2B-compatible Python interface (sandboxes and code interpreter) over Solari Sandboxes. Not affiliated with E2B.
Project-URL: Homepage, https://getsolari.com
Author: Solari
License: MIT
License-File: LICENSE-E2B
License-File: NOTICE
Keywords: code-interpreter,compatibility,e2b,sandbox,solari
Requires-Python: >=3.9
Requires-Dist: solari-core>=0.4.0
Requires-Dist: solari-sandbox>=0.3.0
Provides-Extra: test
Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
Requires-Dist: pytest>=7; extra == 'test'
Description-Content-Type: text/markdown

# solari-e2b-compat

An E2B-compatible Python API on top of [Solari Sandbox](https://getsolari.com). Change the import, keep your sandbox code.

> **Not affiliated with, endorsed by, or sponsored by E2B.** "E2B" is E2B's product name; it appears here only to
> describe API compatibility. The API shapes follow the MIT-licensed `e2b` and `e2b-code-interpreter` SDKs, see
> [NOTICE](./NOTICE). Do not look for this package under `e2b*`.

```python
# before: from e2b_code_interpreter import Sandbox
from solari_e2b.code_interpreter import Sandbox

sbx = Sandbox.create()                      # SOLARI_API_KEY in the environment
execution = sbx.run_code("x = 1\nx + 1")
print(execution.text)                       # "2"
print(sbx.commands.run("echo hello").stdout)
sbx.files.write("/tmp/a.txt", "hi")
sbx.kill()
```

The plain `e2b` package maps to `solari_e2b`:

```python
# before: from e2b import Sandbox, AsyncSandbox, Template
from solari_e2b import Sandbox, AsyncSandbox, Template
```

Exports: `Sandbox` (blocking) and `AsyncSandbox` (create, connect, list, kill, pause, snapshots, fork, `commands`, `files`,
`pty`), `Template` / `AsyncTemplate` and the template builder, the E2B exception classes (`SandboxException`,
`TimeoutException`, `NotFoundException`, `FileNotFoundException`, `CommandExitException`, `AuthenticationException`, ...),
`SolariCompatUnsupported`, and from `solari_e2b.code_interpreter`: `Sandbox` / `AsyncSandbox` with `run_code` and code
contexts, `Execution`, `Result`, `Context`.

The blocking API runs the async client on one background thread; callbacks you pass (`on_stdout`, ...) run on that thread.
Do not call the blocking API from inside such a callback; use `AsyncSandbox` there.

## Configuration

| | Order |
|---|---|
| API key | `api_key=` option, `SOLARI_API_KEY`, `E2B_API_KEY`: only an `slr_…` Solari key is ever used. A non-`slr_` value (for example a real E2B key) is skipped with a warning (the key is never printed or sent); with no Solari key the call raises |
| Base URL | `api_url=` / `domain=` option (Solari or loopback only, anything else raises), `SOLARI_BASE_URL`, `E2B_API_URL` / `E2B_DOMAIN` (only if they point at getsolari.com or loopback; otherwise ignored with a warning), default `https://api.getsolari.com` |

An E2B key does not work here: use a Solari API key.

## The code-interpreter template

`e2b_code_interpreter` runs in a template with a data-analysis stack (pandas, numpy, scipy, scikit-learn, seaborn,
plotly, ...). Solari builds the equivalent, `code-interpreter-v1`, into your org the first time `Sandbox.create()` is
called without a template (about 80 seconds, once). To do it ahead of time:

```python
from solari_e2b.code_interpreter import build_code_interpreter_template_sync
build_code_interpreter_template_sync()      # or: await build_code_interpreter_template()
```

`SOLARI_CODE_INTERPRETER_TEMPLATE` overrides the template (a name or `tpl_…` id). The package list is
`CODE_INTERPRETER_PACKAGES`; the very large audio, NLP and computer-vision wheels E2B ships (spacy, librosa, opencv,
numba, gensim) are not included.

## What works, what does not

[COMPAT.md](./COMPAT.md) is the support matrix. Anything Solari cannot do raises `SolariCompatUnsupported`
(a `SandboxException`) naming the feature; nothing is silently ignored. The sibling TypeScript package is
`sdk/packages/e2b-compat` (`@solarisdk/e2b-compat`) and follows the same rules.

## Tests

- `python -m pytest`: offline unit tests, a fake gateway.
- `SOLARI_API_KEY=… SOLARI_BASE_URL=https://api-sta.getsolari.com python -m pytest -m live tests/test_live_staging.py`:
  live tests against staging. They create their own sandboxes, snapshots and templates and delete only those.
