Skip to content

AsyncSandbox.run_code output handlers are never awaited #159

Closed

Description

@Pwuts

I pass an async callback to on_error, and get the following warning:

ERROR /app/autogpt_platform/backend/.venv/lib/python3.13/site-packages/e2b_code_interpreter/models.py:444: RuntimeWarning: coroutine 'AsyncSandbox.kill' was never awaited
ERROR   on_error(execution.error)
ERROR RuntimeWarning: Enable tracemalloc to get the object allocation traceback

This is because on_error, on_result etc are called but never actually awaited in parse_output:

def parse_output(
execution: Execution,
output: str,
on_stdout: Optional[OutputHandler[OutputMessage]] = None,
on_stderr: Optional[OutputHandler[OutputMessage]] = None,
on_result: Optional[OutputHandler[Result]] = None,
on_error: Optional[OutputHandler[ExecutionError]] = None,
):
data = json.loads(output)
data_type = data.pop("type")
if data_type == "result":
result = Result(**data)
execution.results.append(result)
if on_result:
on_result(result)
elif data_type == "stdout":
execution.logs.stdout.append(data["text"])
if on_stdout:
on_stdout(OutputMessage(data["text"], data["timestamp"], False))
elif data_type == "stderr":
execution.logs.stderr.append(data["text"])
if on_stderr:
on_stderr(OutputMessage(data["text"], data["timestamp"], True))
elif data_type == "error":
execution.error = ExecutionError(data["name"], data["value"], data["traceback"])
if on_error:
on_error(execution.error)
elif data_type == "number_of_executions":
execution.execution_count = data["execution_count"]

Activity

  1. linear commented on Oct 25, 2025

    @linear
  2. mishushakov commented on Oct 25, 2025

    @mishushakov
    Member

    Hey, can you provide us a sample reproduction code where the issue surfaces? I need bit more context here.

  3. Pwuts commented on Oct 26, 2025

    @Pwuts
    Author

    This is where it occurs for me: https://github.com/Significant-Gravitas/AutoGPT/blob/e06e7ff33f20a8ec6990d44a7889cc9ff0720670/autogpt_platform%2Fbackend%2Fbackend%2Fblocks%2Fcode_executor.py#L116-L120

    sandbox.kill() returns a promise, which is awaitable and allowed by the type of on_error, but like I mentioned parse_output doesn't await the result if it's awaitable, causing that warning and keeping the callback from running properly.

  4. self-assigned this
    on Oct 27, 2025
  5. jakubno commented on Oct 27, 2025

    @jakubno
    Member

    Thanks for reporting, fix in #160

  6. jakubno commented on Oct 27, 2025

    @jakubno
    Member

    This should be fixed in https://github.com/e2b-dev/code-interpreter/releases/tag/%40e2b%2Fcode-interpreter-python%402.2.1

    If you still see the error, feel free to reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions