fix(workspace): support e2b self-hosted gateway routing#1896
Open
Posartor wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope Version
Current main branch.
Description
This PR fixes
E2BWorkspacecompatibility with self-hosted E2B deployments.E2BWorkspacestarts an AgentScope MCP gateway inside the E2B sandbox. The gateway listens on the workspace gateway port, which defaults to5600, and all MCP services registered in the workspace are accessed through this gateway.Before this change, the host-side
GatewayClientalways used E2B's default subdomain-based port routing:with:
X-Access-Token: <traffic_access_token>This works for the default E2B cloud routing, but it does not work for self-hosted deployments where sandbox traffic is exposed through a shared client-proxy URL such as:
For these deployments, the client-proxy needs the target sandbox and port to be provided through routing headers:
This PR updates the E2B workspace routing logic to support that mode.
The updated behavior is:
sandbox_url: keep the existing default E2B cloud routing withsandbox.get_host(gateway_port)andX-Access-Tokensandbox_url: use the configured shared proxy URL and route the request withE2b-Sandbox-Id/E2b-Sandbox-PortChanges include:
api_urlandsandbox_urlparameters toE2BWorkspaceapi_urlandsandbox_urlto E2B SDK callssandbox_urlas the host-side gateway base URL when configuredE2b-Sandbox-IdandE2b-Sandbox-Portheaders for self-hosted gateway routingsandbox.get_host(port)+X-Access-Tokenbehavior for default E2B cloud routingapi_urlandsandbox_urlforwarding toE2BWorkspaceManagerCloses #1895
Root Cause
E2BWorkspacestarts an in-sandbox MCP gateway ongateway_port, which defaults to5600, and_wait_for_gateway()waits for it by probing:Before this change,
base_urlwas always resolved through:This assumes E2B subdomain-based port routing, where the target sandbox and port are encoded in the host name.
Self-hosted E2B deployments may expose sandbox traffic through a shared client-proxy URL instead. In that routing mode, the target sandbox and port must be sent through headers:
The gateway was already started successfully inside the sandbox:
However, the previous host-side
GatewayClientdid not use the configured shared sandbox proxy URL or these routing headers, so the request was not routed to sandbox port5600. As a result, the host-side health check timed out even though the gateway was already running inside the sandbox.Test
Pre-commit
Result: passed after normalizing line endings in
src/agentscope/app/workspace_manager/_e2b_workspace_manager.py.Compile check
Result: passed.
Self-hosted E2B validation
Verified with a self-hosted E2B deployment using separate API and sandbox proxy endpoints:
Before the fix, initialization failed while waiting for the gateway health check:
After the fix, the workspace initialized successfully and the MCP gateway was reachable through header-based sandbox routing.
Checklist