Browse modules

e2b

v0.1.0 · compiled with katari 0.1.0

Overview

from the package README

e2b — run Python in a sandbox, as a Katari tool

A single module, e2b, plus its FFI sidecar src/e2b.ts: run Python in an e2b sandbox and hand the result back to the model. The sandbox is owned by the provider and shared by every call in its scope — a stateful kernel, so variables, imports, and files persist across the model's steps.

  • e2b.run_python(code) — the tool: execute Python, return its stdout / value / error text.
  • e2b.provider(api_key = ...) — opens ONE sandbox lazily on first use and shares it for the extent of the continuation, so the model's steps build on each other's state.

The low-level externals (e2b_open, e2b_run_in) are implemented in the sidecar, which keeps the live sandboxes in a module-level map keyed by session handle and self-heals an expired one.

Secrets / env

  • E2B_API_KEY — your e2b API key. Store it in the runtime: katari env set E2B_API_KEY --secret. It is a string of private, passed straight to the sidecar and never surfaced elsewhere.

Sidecar dependencies

src/e2b.ts imports @e2b/code-interpreter and @katari-lang/port. They are declared in package.json; run pnpm install (or npm install) in this package so katari apply can bundle the sidecar. (A pure-Katari consumer that never applies this package does not need them.)

Usage

import e2b
 
agent compute(task: string) -> string with io {
  use e2b.provider(api_key = env.get_secret(key = "E2B_API_KEY"))
  e2b.run_python(code = "print(2 ** 100)")
}

Hand e2b.run_python to an AI loop's tool list to let the model run code on its own.

e2b

5 declarations

e2b_open#

external agent
external agent e2b_open(api_key: string of private) -> string

Open a fresh e2b sandbox and return its session handle — the id every later e2b_run_in replays to reach the same sandbox. The api key never leaves the provider; it is passed straight to the sidecar.

Parameters

api_key
of private
string

Returns

string
Wire view (JSON Schema)

e2b_run_in#

external agent
external agent e2b_run_in(session: string, code: string, api_key: string of private) -> string

Run Python in the sandbox named by session and return its stdout / value / error text. The sidecar reconnects to that sandbox — recreating it under the same handle if it has expired — so state from earlier calls in the same session is still there (only an actually-expired sandbox loses it).

Parameters

session
string
code
string
api_key
of private
string

Returns

string
Wire view (JSON Schema)

e2b_run#

request
request e2b_run(code: string) -> string

Run Python in the ambient e2b session; the provider owns the session handle and threads it through. run_python is the tool an app hands to the model — this is the effect it performs.

Parameters

code
string

Returns

string
Wire view (JSON Schema)

provider#

agent
agent provider[R, effect E](api_key: string of private, continuation: agent(value: null) -> R with {...E, e2b_run}) -> R with E | io

Provide an e2b session for the extent of the continuation: ONE sandbox, opened lazily on the first run_python and shared by every call after, so the model's steps build on each other's state. The session lives as long as this provider scope — wrap a single turn in its own use e2b.provider(...) for strict per-turn isolation.

Generics

Rtype
Eeffect

Parameters

api_key
of private
string
continuation
agent
input
object
value
null
output
R
effects
override
base
E
overrides

Returns

R

Effects

one of
E
io

Inferred type

agent(api_key: string of private, continuation: agent(value: null) -> T0 with e2b_run | E1) -> T0 with E1 | io

Wire view — the wire shape is fixed at the call site, where the generic parameters are instantiated.

run_python#

agent
agent run_python(code: string) -> string

Tool: execute Python code and return its output. Runs in a PERSISTENT sandbox shared across this conversation — variables, imports, and files you defined in earlier calls are still available, so build on them instead of repeating work. (If something you expected is missing, just define it again.)

Parameters

code
string

Returns

string

Inferred type

agent(code: string) -> string with e2b_run
Wire view (JSON Schema)