Throw descriptive error when sandbox is killed mid-request#291
Throw descriptive error when sandbox is killed mid-request#291mishushakov wants to merge 3 commits into
Conversation
When the sandbox is killed or times out while a request to the Jupyter server is in flight (runCode/run_code or context management), the SDKs surfaced a raw socket error (e.g. ECONNRESET). Now they detect the closed connection, confirm the sandbox is gone via its health check, and throw a descriptive SandboxError/SandboxException instead. If the sandbox is still running (or its state can't be determined), the original error propagates unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
PR SummaryMedium Risk Overview On JavaScript, On Python (sync and async), Reviewed by Cursor Bugbot for commit 17cce6a. Bugbot is set up for automated code reviews on this repo. Configure here. |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Matches the existing 502 mapping in extractError/extract_exception and the base SDK convention: a dead sandbox surfaces as TimeoutError / TimeoutException. When the health probe is inconclusive or the sandbox is still running, the original transport error propagates unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 17cce6a. Configure here.
| sandboxTest.skipIf(isDebug)( | ||
| 'runCode throws a descriptive error when the sandbox is killed during execution', | ||
| async ({ sandbox }) => { | ||
| const execution = sandbox.runCode('import time; time.sleep(60)') |
There was a problem hiding this comment.
Kill test sleep too short
Medium Severity
The new kill-during-execution tests use time.sleep(60) while runCode/run_code rely on the default execution timeout (60s in JS, 300s in Python). That ratio is far below the project’s 10×/100× guidance for interrupt-style execution tests, so on JS the run can hit the default timeoutMs abort around the same time as the sleep ends instead of staying in-flight when the sandbox is killed.
Additional Locations (2)
Triggered by learned rule: Test sleep durations must far exceed test timeouts
Reviewed by Cursor Bugbot for commit 17cce6a. Configure here.


When the sandbox is killed or times out while a request is in flight,
runCode/run_codeand the context-management methods surfaced a raw socket error (e.g.ECONNRESETon Bun,TypeError: fetch failedon Node,httpx.ReadError/RemoteProtocolErrorin Python). Both SDKs now detect the closed connection across runtimes, confirm via the sandbox health check that it's actually gone, and throw a descriptiveSandboxError/SandboxExceptionsuggestingtimeoutMs/.setTimeoutinstead. If the sandbox is still running or its state can't be determined, the original error propagates unchanged so genuine network issues aren't masked. Includes kill-during-execution tests for JS, Python sync, and Python async (verified against the live API on Node and Bun), plus a patch changeset for both packages.🤖 Generated with Claude Code