feat: add Stagehand code-mode MCP image - #2643
Open
shrey150 wants to merge 2 commits into
Open
Conversation
|
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Architecture diagram
sequenceDiagram
participant Host as Agent Application
participant MCP as Sandbox MCP Gateway
participant MicroVM as Firecracker MicroVM
participant Stdio as Stagehand Code-Mode MCP (Stdio)
participant JS as Generated JavaScript (Untrusted)
participant Reg as GHCR Container Registry
participant CI as CI Pipeline
Note over Host,MicroVM: PR introduces sandboxed OCI image architecture
%% Build Phase
CI->>CI: Build multi-stage Dockerfile.codemode
CI->>Reg: Publish immutable sha-<commit> tags
CI->>Reg: Attach build-provenance attestation
Reg-->>CI: Image available at ghcr.io/browserbase/stagehand-codemode
%% Image Pull and Deployment
Host->>Reg: Pull image by digest (sha-<commit>)
Reg-->>Host: Stagehand code-mode OCI image
Host->>MicroVM: Launch Firecracker microVM with image
Host->>MicroVM: Pass only BROWSERBASE_API_KEY & PROJECT_ID
%% Runtime Flow Inside Sandbox
MicroVM->>Stdio: Start stdio-server.mjs as non-root "node" user
Host->>MCP: Authenticated Streamable HTTP request
MCP->>MicroVM: Forward MCP request via stdio
MicroVM->>Stdio: Route to Stagehand MCP server
Stdio->>Stdio: Initialize with protocolVersion "2025-06-18"
alt Code Execution Request
Stdio->>Stdio: tools/list response: ["code_execute"]
Host->>MCP: Invoke code_execute tool
MCP->>MicroVM: Forward invocation
MicroVM->>Stdio: Execute generated JavaScript
Stdio->>JS: Evaluate untrusted code
JS-->>Stdio: Execution result
Stdio->>Stdio: Run Stagehand browser actions
Stdio-->>MicroVM: Return result
MicroVM-->>MCP: Stream response back
MCP-->>Host: Tool execution output
else Discovery Smoke (CI Phase)
CI->>Stdio: docker run --network none
CI->>Stdio: Send initialize & tools/list MCP messages
Stdio-->>CI: Response with code_execute tool
note over CI,Stdio: NEW: Network-disabled MCP verification
end
%% Cleanup
Host->>MicroVM: Terminate agent run / timeout
MicroVM->>Stdio: Close stdin (trigger graceful shutdown)
MicroVM->>MicroVM: Destroy complete microVM boundary
Note over Host,Reg: Security boundaries enforced throughout
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Contributor
Author
|
This does not need to land before launch |
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.
Why
Stagehand code mode evaluates model-generated JavaScript. A normal host process or standalone container is not a sufficient boundary for untrusted code because that code inherits the process's filesystem, environment, and network access.
This layer packages the canonical stdio MCP server as an unprivileged OCI image and documents how to run that image inside a Firecracker microVM or equivalent sandbox. The image is portable packaging; the sandbox provider supplies the security boundary.
Relationship to the framework stack
#2620 remains the common parent for two independent paths:
The framework PRs do not need this image to merge. E2B can clone, install, and build the exact pinned Stagehand source inside its Firecracker microVM. This PR can land independently when its publishing and provenance workflow is ready.
What changed
Dockerfile.codemodethat builds the exact workspace implementation and runs the stdio server as the non-rootnodeuserghcr.io/browserbase/stagehand-codemodeonly on an explicit tag or manual publish; it never publisheslatestE2E Test Matrix
docker build --platform linux/amd64 -f Dockerfile.codemode -t stagehand-codemode:foundation .docker run --rm -i --network none --platform linux/amd64 stagehand-codemode:foundation{"status":"PASS","network":"none","tools":["code_execute"]}code_executewithout network access.nodeas its user and Node.js 24.19.0 as its runtime.The discovery smoke intentionally does not execute browser code because it runs with
--network none. The downstream framework PRs carry the live Browserbase and sandbox-containment proofs.Changeset
None. This adds packaging, documentation, and CI without changing a published package API or runtime default.