Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run commands in sandbox through Python SDK #581

Open
jayv-tech opened this issue Feb 15, 2025 · 3 comments
Open

Unable to run commands in sandbox through Python SDK #581

jayv-tech opened this issue Feb 15, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@jayv-tech
Copy link

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.

@jayv-tech jayv-tech added the bug Something isn't working label Feb 15, 2025
Copy link

linear bot commented Feb 15, 2025

@mishushakov
Copy link
Member

Hey! Thanks for reporting. Unfortunately, I was unable to reproduce, can you provide a full example?

@jayv-tech
Copy link
Author

I just tried to use the GPT 4o model to generate an SVG file and list and watch the directory to download that later. Even running the simple commands after initiating the sandbox and manually connecting to it, results in that specified error.

Now, I have tried and used the run_code method to bypass this:
result = sandbox.run_code(f'ls -l {remote_dir}', 'bash')

Only this works. Also, any attempt to read and save an image file will result in an error unless we specify 'bytes' param along with it.

Something like this:

remote_file = "/home/user/test.svg"

local_filename = "test.svg"

content = sandbox.files.read(remote_file, 'bytes')

with open(local_filename, "wb") as f:
    f.write(content)
print(f"Downloaded new SVG.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants