Skip to content

Unable to run commands in sandbox through Python SDK #581

Open
@jayv-tech

Description

@jayv-tech

Describe the bug
When executing a command using the E2B sandbox code interpreter (even a simple command like ls -l), the SDK returns a streaming response. However, any attempt to print or otherwise access the result (for example, with print(result)) triggers a RuntimeError with the message:

"Attempted to access 'response.content' on a streaming response. Call 'response.read()' first."

Even after trying to explicitly read the stream (using await result.aread() in an async context or result.read() in a synchronous context), the error persists because the package appears to attempt to access the response content before the stream has been fully buffered (atleast, that's what I guess is going on.)

To Reproduce
Steps to reproduce the behavior:

  1. Initialize an E2B sandbox.
  2. Run a simple command. For example:
    result = sandbox.commands.run('ls -l') print(result)
  3. A RuntimeError will raise with the message about accessing response.content on a streaming response.

Expected behavior
The command should be executed properly, and after it completes, accessing the result (or printing it) should not trigger an error.

Browser console output
N/A (This is a Python package issue, not a browser issue.)

Terminal commands & output
Terminal command executed:
result = sandbox.commands.run('ls -l', on_stdout=lambda data: print(data)) print(result)
Terminal output:

RuntimeError: Attempted to access 'response.content' on a streaming response. Call 'response.read()' first.

Screenshots

Image

Desktop (please complete the following information):

  • OS: WSL (Ubuntu 24.04), also tested with native Ubuntu 24.10 system.
  • Python Version: 3.12
  • E2B SDK Version: 1.0.5

Smartphone (please complete the following information):
N/A

Additional context
I also tried the example command from the documentation:

result = sandbox.commands.run('echo hello; sleep 1; echo world', on_stdout=lambda data: print(data), on_stderr=lambda data: print(data))
print(result)

which produces the same error. Even when attempting to call await result.aread() before accessing the result, the error is raised internally within the package. This behavior prevents any downstream access to the full command output, making it impossible to execute any command in the sandbox.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions