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

Results, displays and charts

A result can hold several formats of the same output: text, PNG, HTML, JSON or chart data. Result.formats() lists which ones a display produced.

Example
from e2b_code_interpreter.models import Result

figure = Result(png="iVBORw0KGgo=", text="<Figure size 640x480 with 1 Axes>", is_main_result=False)
print(list(figure.formats()))
print(figure.text)
print(figure.png[:12])

table = Result(html="<table>...</table>", text="   total\n0  120.5", is_main_result=True)
print(list(table.formats()), table.is_main_result)

These are the SDK's Result objects, built the way the parser builds them from result messages. A matplotlib figure arrives as a PNG, base64-encoded, plus a text fallback. A pandas DataFrame as the last expression arrives as HTML and text, and is the main result.

Examplesaving a chart from a real execution
import base64

for result in execution.results:
    if result.png:
        with open("chart.png", "wb") as f:
            f.write(base64.b64decode(result.png))

For an agent, send the model the text of results and keep images for the person: models that read images can take the PNG, but most tool loops pass text. The chart format, when present, holds the plotted data as structured values, useful for rendering an interactive chart in your own UI.

Try it yourself
  • Build a Result with json={"total": 120.5} and print its formats.
  • Print figure._repr_png_().
  • Find the list of formats in Result.formats in the SDK.

Every expert started right here.