Skip to content

Restore port config changes (#490, #535)#540

Draft
ghostwriternr wants to merge 3 commits intomainfrom
restore/port-config-changes
Draft

Restore port config changes (#490, #535)#540
ghostwriternr wants to merge 3 commits intomainfrom
restore/port-config-changes

Conversation

@ghostwriternr
Copy link
Copy Markdown
Member

@ghostwriternr ghostwriternr commented Mar 30, 2026

Summary

Restores the port config changes that were reverted in #536:

Context

#490 changed the container control port from 3000 to 8671, with a legacy fallback for containers still running on 3000. The fallback had gaps that caused failures when rolling out the new SDK version to workers with already-running containers — the same upgrade path production users would hit. #535 attempted to address those gaps.

After reverting and re-investigating, we also discovered a separate platform-level container scheduling issue that compounded the failures. That is being reported to the Containers team separately.


Open with Devin

Muhammad-Bin-Ali and others added 3 commits March 30, 2026 13:37
* Make container control plane port configurable via SANDBOX_CONTROL_PORT env var

* Propagate configurable control port through SDK and shared types

* Update Dockerfiles

* Add tests

* Update existing tests

* Add e2e tests

* Add changeset

* Fix e2e tests

* Bonk changes

* Remove unneeded test + provide templating for control port in docker files

* Update markdown files

* Make port configurable

* Address bonk's comments

* Address Devin comments

* Address Devin

* Change changeset to patch

* Fix missing import

* Move control port validation into the Durable Object (#528)

The configurable control port feature threaded getControlPort
through proxy-side functions (connect, enhanceSession,
proxyTerminal, terminal). This is unnecessary because the DO
already owns defaultPort and handles routing via Container.fetch.

Port validation now uses the cf-container-target-port header in
Sandbox.fetch(), which correctly distinguishes user WebSocket
connections from control-plane WebSockets without fragile path
exemptions. The legacy fallback remap is fixed to work with
custom SANDBOX_CONTROL_PORT values, not just the default.

---------

Co-authored-by: Muhammad Ali <muhammadali@cloudflare.com>
Co-authored-by: Naresh <ghostwriternr@gmail.com>
…holders (#535)

* Resolve CodeInterpreter client lazily via getter

The constructor captured sandbox.client.interpreter once. After the
legacy port fallback recreated this.client, the interpreter kept
using the stale reference, causing instant 500s for all interpreter
calls while exec() worked fine on the new client.

* Add container startup to WebSocket upgrade path

The WebSocket branch of Sandbox.fetch() called super.fetch() without
ensuring the container was started, bypassing the legacy port fallback
entirely. Extract checkContainerState(), startContainer(), and
handleStartupError() from containerFetch() and reuse them in the
WebSocket branch so both transports get identical startup, fallback,
and error classification behavior.

* Accept client-getter in LocalMountSyncManager

Same stale-client pattern as CodeInterpreter: the constructor stored
a direct reference to this.client which went stale after fallback.
Accept a getClient closure instead so active mounts always resolve
the current client.

* Add inline comments at client resolution sites

* Add changeset

* Use canonical logging and stop leaking error messages in responses

Startup error classification now uses logCanonicalEvent() with
credential redaction instead of raw logger calls. Error details are
logged server-side only — response bodies no longer include
e.message in the context field.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 30, 2026

🦋 Changeset detected

Latest commit: 58b2874

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/sandbox Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@540

commit: 58b2874

@github-actions
Copy link
Copy Markdown
Contributor

🐳 Docker Images Published

Variant Image
Default cloudflare/sandbox:0.0.0-pr-540-58b2874
Python cloudflare/sandbox:0.0.0-pr-540-58b2874-python
OpenCode cloudflare/sandbox:0.0.0-pr-540-58b2874-opencode
Musl cloudflare/sandbox:0.0.0-pr-540-58b2874-musl
Desktop cloudflare/sandbox:0.0.0-pr-540-58b2874-desktop

Usage:

FROM cloudflare/sandbox:0.0.0-pr-540-58b2874

Version: 0.0.0-pr-540-58b2874


📦 Standalone Binary

For arbitrary Dockerfiles:

COPY --from=cloudflare/sandbox:0.0.0-pr-540-58b2874 /container-server/sandbox /sandbox
ENTRYPOINT ["/sandbox"]

Download via GitHub CLI:

gh run download 23745698168 -n sandbox-binary

Extract from Docker:

docker run --rm cloudflare/sandbox:0.0.0-pr-540-58b2874 cat /container-server/sandbox > sandbox && chmod +x sandbox

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 8 additional findings.

Open in Devin Review

@ghostwriternr ghostwriternr marked this pull request as draft March 30, 2026 13:03
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.

2 participants