Skip to content

[Bug] sandbox.connect() fails with "Unexpected server response: 101" on Bun runtime + express #234

@nalaso

Description

@nalaso

When using @codesandbox/sdk (v2.4.2) with Bun runtime (v1.3.4), calling sandbox.connect() throws:

error: Unexpected server response: 101
  at errorListener (node_modules/@codesandbox/sdk/dist/esm/index.js:8444:16)
[testListFiles] Error: 8439 |     cleanInitialListeners();
8440 |     resolve(new WebSocketClient(ws));
8441 |   };
8442 |   const errorListener = ({ message }) => {
8443 |     cleanInitialListeners();
8444 |     reject(new Error(message));
                      ^
error: Unexpected server response: 101

Steps to Reproduce:

Create a backend server using Bun + Express
Install @codesandbox/sdk
Resume a sandbox and attempt to connect:

const sdk = new CodeSandbox(apiKey);
const sandbox = await sdk.sandboxes.resume(sandboxId);
console.log(sandbox.bootupType); // Logs "RUNNING"
const client = await sandbox.connect(); // ❌ Fails here

Expected: WebSocket connection should succeed.

Actual: Throws "Unexpected server response: 101" even though sandbox is already RUNNING.

Environment:

SDK: @codesandbox/[email protected]
Runtime: Bun 1.3.4
OS: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions