Skip to content

Conversation

@alt-glitch
Copy link
Contributor

Summary

Add a new E2BREPL environment that runs Python code in E2B sandboxes, following the same HTTP broker pattern as ModalREPL and PrimeREPL.

Changes

  • rlm/environments/e2b_repl.py - Full E2BREPL implementation using HTTP broker pattern
  • examples/e2b_repl_example.py - Example demonstrating basic code execution and LLM queries
  • rlm/environments/__init__.py - Register "e2b" environment
  • rlm/core/types.py - Add "e2b" to EnvironmentType
  • pyproject.toml - Add e2b optional dependency (e2b-code-interpreter>=0.0.11)

Key Implementation Details

  • Uses e2b-code-interpreter SDK with Sandbox.create() API
  • Runs Flask broker on port 8889 (not 8888, which E2B uses for Jupyter)
  • Uses sandbox.get_host(port) for public URL access
  • Supports llm_query(), llm_query_batched(), FINAL_VAR()
  • State persistence across code executions via dill serialization

Usage

# Install with e2b support
uv pip install -e ".[e2b]"

# Set API key
export E2B_API_KEY=your_key

# Run example
python -m examples.e2b_repl_example

Example Output

============================================================
E2B REPL Example
============================================================

[1] Basic code execution (no LLM handler)
----------------------------------------
E2B sandbox created, ID: ikk8xw53nne4bytcdg87t
Executed: x = 1 + 2
Locals: {'x': '3'}
Executed: print(x * 2)
Stdout: 6
FINAL_VAR('answer'): 42

[2] Code execution with LLM handler
----------------------------------------
LM Handler started at ('127.0.0.1', 49536)
E2B sandbox created, ID: i0o2ud044jn49rgy4pvp8
Broker URL: https://8889-i0o2ud044jn49rgy4pvp8.e2b.app
Executed: response = llm_query('What is 2+2?')
Stderr: (none)
Response: Mock response to: What is 2+2?

Executed: responses = llm_query_batched([...])
Result: Got 3 responses
First response: Mock response to: Question 1

============================================================
Done!
============================================================

Test Plan

  • Basic code execution works
  • State persistence works across calls
  • FINAL_VAR() extracts variables correctly
  • LLM handler integration works (single and batched queries)
  • Broker communication works over E2B public URL
  • Ruff passes all checks

Add a new E2BREPL environment that runs Python code in E2B sandboxes,
following the same HTTP broker pattern as ModalREPL and PrimeREPL.

Changes:
- Add rlm/environments/e2b_repl.py with E2BREPL class
- Add examples/e2b_repl_example.py demonstrating usage
- Register "e2b" environment in environments/__init__.py
- Add "e2b" to EnvironmentType in core/types.py
- Add e2b optional dependency to pyproject.toml

Key implementation details:
- Uses e2b-code-interpreter SDK with Sandbox.create() API
- Runs Flask broker on port 8889 (8888 is used by E2B's Jupyter)
- Uses sandbox.get_host(port) for public URL access
- Supports llm_query(), llm_query_batched(), FINAL_VAR()
@alexzhang13 alexzhang13 self-requested a review January 10, 2026 06:23
@alexzhang13
Copy link
Owner

I'll take a look at this when I have time, I do want to add E2B support.

alexzhang13 and others added 4 commits January 10, 2026 01:24
Keep both E2B and Prime sandbox support.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@alt-glitch alt-glitch force-pushed the sid/add-e2b-sandboxes branch from 8976ee1 to fddfd14 Compare January 12, 2026 07:53
@alt-glitch alt-glitch marked this pull request as ready for review January 12, 2026 07:54
@alt-glitch
Copy link
Contributor Author

@alexzhang13 ready for review.

To test, run:

uv run python examples/e2b_repl_example.py

Align E2BREPL with other environments (DockerREPL, ModalREPL, PrimeREPL)
by adding the persistent parameter introduced in PR alexzhang13#40. Raises
NotImplementedError when persistent=True since E2BREPL doesn't yet
implement the SupportsPersistence protocol.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants