E2B icon indicating copy to clipboard operation
E2B copied to clipboard

[Bug]: Python SDK files.read of files over ~500 KB fails at random with too_many_data_frames (pyqwest h2)

Open wei-fh opened this issue 1 month ago • 4 comments

Sandbox ID or Build ID

Reproduces in any fresh sandbox from the default template (AsyncSandbox.create()), so no particular sandbox is involved.

Environment

  • e2b 2.59.0, pyqwest 0.12.0 (both the latest on PyPI)
  • Python 3.12, AsyncSandbox
  • Seen from macOS (Darwin) and from a Linux container on Google Cloud Run

Timestamp of the issue

2026-10-23 17:15 UTC (first seen on our deployed service); reproduced the same day

Frequency

Happens intermittently, more often the larger the file: no failures in 40 reads at 250 KB and below, about 1 read in 10 at 500 KB–1 MB, about half of all reads at 2–3 MB, and every read at 4.5 MB and 8 MB.

Expected behavior

await sandbox.files.read(path, "bytes") (or "stream") returns the file's contents for a file of a few MB.

Actual behavior

The read raises:

httpx.ReadError: Error reading content: request or response body error: error reading a body from connection: connection error detected: detected excessive load generating behavior (b"too_many_data_frames")

detected excessive load generating behavior is h2's text for ENHANCE_YOUR_CALM, and too_many_data_frames / "too many small DATA frames" are strings in the h2 that pyqwest's _pyqwest.abi3.so bundles (a git checkout of h2, h2-937e4a7e831fda7e/286de9d). So the SDK's own client seems to tear down the connection because the response from the sandbox proxy arrives as many small DATA frames. Retrying the same read usually succeeds.

Measured from one fresh sandbox, random bytes, 10 or 20 reads per size:

Size read(..., "bytes") failed read(..., "stream") failed
50 KB 0/20 0/20
250 KB 0/20 0/20
500 KB 2/20 2/20
700 KB 3/20 2/20
0.8–1.1 MB 2/10 each 1–3/10
1.2–1.5 MB 3–4/10 3/10
1.75–3 MB 4–5/10 5/10
4.5 MB, 8 MB 3/3, 3/3 not tried

Issue reproduction

import asyncio
import os

from e2b import AsyncSandbox


async def main() -> None:
    sandbox = await AsyncSandbox.create(timeout=300)
    try:
        for mb in (0.25, 0.5, 1, 2, 4.5):
            size = int(mb * 1024 * 1024)
            await sandbox.files.write(f"/tmp/blob-{mb}.bin", os.urandom(size))
            failed = 0
            for _ in range(10):
                try:
                    assert len(await sandbox.files.read(f"/tmp/blob-{mb}.bin", "bytes")) == size
                except Exception as exc:
                    failed += 1
                    last = f"{type(exc).__name__}: {exc}"
            print(f"{mb} MB: {failed}/10 failed", last if failed else "")
    finally:
        await sandbox.kill()


asyncio.run(main())

Additional context

We hit this reading a full-page JPEG screenshot (hundreds of KB to a few MB) out of the sandbox, and are working around it by retrying reads that raise httpx.ReadError. A read that fails every time at 4.5 MB and above means the retry cannot help for larger files, so we expect the fix is either the h2 limit in pyqwest's bundled h2 or how the proxy frames file responses.

wei-fh avatar Oct 23 '26 19:10 wei-fh

Triage

  • type: bug
  • priority: high
  • complexity: medium
  • affected_area: python-sdk/filesystem (pyqwest HTTP/2 transport / sandbox proxy response framing)
  • actionable: yes
  • needs_clarification: false
  • summary: In the Python SDK (e2b 2.59.0, pyqwest 0.12.0), files.read of files over ~500 KB fails intermittently, and every time at 4.5 MB and above, with httpx.ReadError ... too_many_data_frames (h2 ENHANCE_YOUR_CALM). The failure rate rises with file size and a minimal repro is included. Assumption: the fix belongs in the pyqwest/h2 client limits or in how the proxy frames file responses.

Written by Devin

Verified from the SDK side, which narrows where this can be fixed:

  • The too_many_data_frames / "too many small DATA frames" tripwire (surfaced as ENHANCE_YOUR_CALM) is compiled into pyqwest's bundled h2 fork (h2-937e4a7e831fda7e/286de9d — the same checkout the report cites; I confirmed the strings in pyqwest 0.12.0's _pyqwest.abi3.so). So the SDK's own HTTP client is what tears the connection down, matching the report's analysis.
  • pyqwest 0.12.0 exposes no knob for that limit: the full HTTPTransport kwarg list (checked against the shipped .pyi stub) is TLS / proxy / pool / timeout / redirect / compression knobs only. The SDK's transport factory (e2b/api/client_async.get_pyqwest_transport) passes exactly that surface, so there is nothing the SDK can set today to raise or relax the frame-flood limit.

That leaves the fix surface as: (a) pyqwest exposing a setting for the h2 frame-flood limit, or (b) the proxy/envd coalescing file responses into larger DATA frames server-side — (b) also fixes every other h2 client hitting the same endpoint.

Workaround that works today if anyone needs it: pin HTTP/1.1 via E2B_HTTP_VERSION=1.1 (or http_version="1.1" in the connection config). That sidesteps the h2 flood check entirely — at the cost of losing h2 multiplexing for that session.

Happy to verify a candidate fix against a local repro if one is proposed.

nosmile99 avatar Oct 24 '26 03:10 nosmile99

/repro

mishushakov avatar Oct 26 '26 16:10 mishushakov

@wei-fh thanks for the detailed report and repro script. The fix shipped in the Python SDK e2b 2.62.1 via https://github.com/e2b-dev/E2B/pull/2088: Sandbox.files.read / AsyncSandbox.files.read now download over HTTP/1.1 regardless of http_version, so h2's too_many_data_frames limit no longer applies. (e2b-code-interpreter 2.11.8 picks it up too.)

pip install -U e2b==2.62.1

Written by Devin