Skip to content

Client can't connect to server in sbx sandbox #50533

Closed

Description

@the4thamigo-uk

Description

Summary

I am launching opencode in an sbx sandbox with the following command :

sbx run opencode . -- --hostname 0.0.0.0 --port 4096
Although the server binds to 0.0.0.0 fine, the client side fails to connect in the sandbox, with the error :

Error: dial tcp4 0.0.0.0:4096: connect: connection refused

at <anonymous> (/$bunfs/root/chunk-pf78enbq.js:8:7615)
at processTicksAndRejections (native:7:39)

I can replicate this in the sandbox with a separate opencode serve ... and opencode attach ... commands. the serve works fine, the attach fails with the same error.

The problem seems to be that the url that the client uses to connect is constructed from the passed hostname (0.0.0.0), and this is a non-routable address for connections.

Proposed fix

I suggest translating the wildcard bind address to a loopback address when the TUI worker returns the URL to its local client.

For example, in packages/opencode/src/cli/tui/worker.ts:

async server(input: { port: number; hostname: string; mdns?: boolean; cors?: string[] }) {
if (server) await server.stop(true)

server = await Server.listen(input)

const url = new URL(server.url)

if (input.hostname === "0.0.0.0") {
url.hostname = "127.0.0.1"
}

return { url: url.toString() }
}

Other Information

There seems to be similar logic in this code :

https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/cli/cmd/web.ts?utm_source=chatgpt.com#L49-L51

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on Sep 22, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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