E2BE2B SDK 2.50 · Code Interpreter 2.10 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
10 small wins to finish your pathNext lesson

Errors: reported, not raised

An exception in the sandbox's code does not raise in your program. It arrives as an error message and becomes execution.error, which your code must check.

Example
import json

from e2b_code_interpreter.models import Execution, parse_output

execution = Execution()
for message in [
    {"type": "stdout", "text": "starting\n", "timestamp": 1},
    {"type": "error", "name": "ZeroDivisionError", "value": "division by zero",
     "traceback": "Traceback (most recent call last):\n  Cell In[1], line 2\nZeroDivisionError: division by zero"},
]:
    parse_output(execution, json.dumps(message))
Example
print(execution.error.name, "|", execution.error.value)
print(execution.error.traceback.splitlines()[-1])
print(execution.logs.stdout)
print(execution.text)

The cell printed starting, then failed. execution.error has the exception's name, value and the traceback as text; there is no main result. run_code returned normally: the SDK's parser records an error message and moves on.

What does raise

SituationIn your program
The code raises inside the sandboxNo exception; execution.error is set
The code runs longer than timeoutTimeoutException, from the SDK's httpx.ReadTimeout handling
The sandbox was killed or expiredAn API error from the HTTP response
No key, or an invalid keyAuthenticationException

For an agent this split is right: a model should read a KeyError and fix its code, but your program should stop on a sandbox that no longer exists. timeout=0 in run_code removes the time limit, which an agent should never do.

Try it yourself
  • Print execution.error.to_json().
  • Find format_execution_timeout_error in the SDK and read its message.
  • Write an if that returns the error text when there is one and the result otherwise.

This is what real progress feels like.