Skip to content

Conversation

@hwlzc
Copy link

@hwlzc hwlzc commented Feb 12, 2026

Summary

  • When E2B_SANDBOX_URL is set (local/self-hosted environments), the code interpreter SDK's Jupyter requests (run_code, create_code_context, etc.) bypass E2B_SANDBOX_URL and are sent directly to the hostname-based URL (e.g. https://49999-{sandbox_id}.e2b.app), which fails in local setups.
  • The base SDK (e2b) correctly handles this via get_sandbox_url(), but the code interpreter's _jupyter_url uses get_host() directly.
  • This fix updates _jupyter_url to respect E2B_SANDBOX_URL and adds E2b-Sandbox-Id / E2b-Sandbox-Port headers for local client-proxy routing.
  • Both sync (Sandbox) and async (AsyncSandbox) classes are fixed.
  • Cloud users are unaffected (E2B_SANDBOX_URL is not set in cloud flow).

Test plan

  • Tested with local E2B infrastructure (API at localhost:3000, client-proxy at localhost:3002)
  • Verified run_code() works with stateful execution (variable persistence across calls)
  • Cloud environment regression test (no behavioral change expected when E2B_SANDBOX_URL is not set)

…DBOX_URL is set

When E2B_SANDBOX_URL is set (local/self-hosted environments), the base
SDK correctly routes envd API requests through the client-proxy via
`get_sandbox_url()`. However, the code interpreter SDK's `_jupyter_url`
property constructs its own URL using `get_host()`, bypassing
E2B_SANDBOX_URL entirely. This causes Jupyter requests (run_code, etc.)
to be sent to the production E2B API instead of the local client-proxy,
resulting in 502 errors.

This fix:
- Updates `_jupyter_url` to use E2B_SANDBOX_URL when available
- Adds `E2b-Sandbox-Id` and `E2b-Sandbox-Port` headers for local
  client-proxy routing (supported in local mode)
- Applies to both sync and async Sandbox classes

Cloud users are unaffected as E2B_SANDBOX_URL is not set in that flow.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant