Skip to content

Conversation

@Code42Cate
Copy link
Contributor

@Code42Cate Code42Cate commented Oct 29, 2025

Sandboxes should be removed automatically, not with explicit kill().

This breaks especially the research-agent use-case where you want to open the generated page after the agent is run, or the mcp client ones where you want to connect the gateway to claude etc.


Note

Remove explicit sandbox.kill() from MCP example scripts, keeping sandboxes alive while still closing MCP connections where used.

  • Examples:
    • Remove explicit sandbox.kill() cleanup across MCP examples to keep sandboxes available post-run:
      • examples/mcp-browserbase-js/index.ts — remove sandbox kill; close MCPServerStreamableHttp on completion.
      • examples/mcp-research-agent-js/index.ts — remove sandbox kill; close MCPServerStreamableHttp on completion.
      • examples/mcp-claude-code-js/index.ts, examples/mcp-client-js/index.ts, examples/mcp-custom-server-js/index.ts, examples/mcp-custom-template-js/index.ts, examples/mcp-groq-exa-js/index.ts — remove sandbox kill lines only.

Written by Cursor Bugbot for commit 3c6a013. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Background Server Terminates Prematurely

The code starts a background web server and prints a URL for users to access the results, but then the function returns immediately and the process exits, terminating the sandbox before the user can access the web server. Removing sandbox.kill() doesn't keep the sandbox alive—the process still exits naturally when the async function completes. The PR description explicitly states this breaks "the research-agent use-case where you want to open the generated page after the agent is run." The function needs to keep the process alive (e.g., with a signal handler like in custom-sandbox-domain-proxy example) to allow users to actually access the hosted results.

examples/mcp-claude-code-js/index.ts#L58-L62

const webserverUrl = sandbox.getHost(3000);
console.log(`\nResearch completed successfully!`);
console.log(`Visit the research results at: http://${webserverUrl}/index.html`);
console.log(`The page contains the paper summary and author information`);

Fix in Cursor Fix in Web


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.

3 participants