Skip to content

fix: defer sandbox cleanup until stream completes#5

Merged
sweetmantech merged 1 commit intomainfrom
sweetmantech/myc-4186-bash-agent-commands-failing-is-this-an-env-error
Feb 9, 2026
Merged

fix: defer sandbox cleanup until stream completes#5
sweetmantech merged 1 commit intomainfrom
sweetmantech/myc-4186-bash-agent-commands-failing-is-this-an-env-error

Conversation

@sweetmantech
Copy link
Copy Markdown

Summary

  • Root cause: The finally block in /api/agent/route.ts called sandbox.stop() immediately when createAgentUIStreamResponse returned the Response object — before the client started consuming the stream. This destroyed the Vercel Sandbox before the agent could execute any bash tool calls, causing every command to fail with [Tool Error] Tool execution error.
  • Fix: Replaced the finally block with a TransformStream wrapper that pipes the response body through and calls sandbox.stop() in the .finally() callback of pipeTo(), ensuring cleanup happens only after the stream completes (or errors/disconnects).
  • Not an ENV error: The issue was a sandbox lifecycle bug, not a missing environment variable.

Test plan

  • Run agent "What is just-bash?" and verify bash commands execute successfully
  • Verify multi-turn agent conversations work (agent "list the files" then agent "show me the README")
  • Verify sandbox cleanup still happens after stream ends (no sandbox leaks)
  • Verify error handling: if sandbox creation fails, the error propagates correctly

🤖 Generated with Claude Code

The `finally` block was calling `sandbox.stop()` immediately when
`createAgentUIStreamResponse` returned, before the client consumed
the stream. This killed the sandbox before any agent tool calls
could execute, causing all bash commands to fail with
"[Tool Error] Tool execution error".

Now uses a TransformStream wrapper with `pipeTo().finally()` to
ensure sandbox cleanup happens after streaming completes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
just-bash Ready Ready Preview Feb 9, 2026 2:25pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 9, 2026

Warning

Rate limit exceeded

@sweetmantech has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 42 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sweetmantech/myc-4186-bash-agent-commands-failing-is-this-an-env-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sweetmantech sweetmantech merged commit 96c6b9c into main Feb 9, 2026
2 checks passed
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