-
Couldn't load subscription status.
- Fork 30
Make control plane port configurable via SANDBOX_CONTROL_PLANE_PORT #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Make control plane port configurable via SANDBOX_CONTROL_PLANE_PORT #161
Conversation
Co-Authored-By: Naresh Ramesh <[email protected]>
Add SANDBOX_CONTROL_PLANE_PORT environment variable to configure the control plane port (default: 3000) used for internal communication between the Sandbox DO and the container. This resolves port conflicts when users need port 3000 for their applications. The port can be configured in both the Worker environment and the Dockerfile. Additionally, improve error detection and logging for port conflicts. When the control plane port is already in use, the container now provides clear error messages with actionable solutions. Co-Authored-By: Naresh Ramesh <[email protected]>
🦋 Changeset detectedLatest commit: bee3e07 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Claude Code ReviewSummary: This PR makes the control plane port configurable to resolve port conflicts. The implementation is mostly solid with good test coverage. Issues Found1. Validation inconsistency between SDK and container (sandbox.ts:96-101 vs config.ts:96-97) The SDK validates the port range as 1-65535, but the container uses the same range. However, both should enforce the 1024-65535 range consistently with the Fix: Both config validation points should use the same logic as 2. Port conflict detection is fragile (index.ts:60-61) The error handling relies on string matching Fix: Check 3. Async getControlPlanePort in proxyToSandbox (request-handler.ts:43) The method Fix: Remove Minor Observations
VerdictApprove with suggested fixes for the validation inconsistency and async overhead. |
Remove all hard coded port 3000 references in request routing and validation. Includes unit tests for configuration parsing and dynamic validation.
commit: |
🐳 Docker Image PublishedFROM cloudflare/sandbox:0.0.0-pr-161-e815f30Version: You can use this Docker image with the preview package from this PR. |
Resolves port conflict issues by making the control plane port configurable.
Changes
This PR adds support for configuring the control plane port (default: 3000) via the
SANDBOX_CONTROL_PLANE_PORTenvironment variable. This allows users to avoid port conflicts when port 3000 is already in use by their application.Key Changes:
Container Runtime (
packages/sandbox-container/):CONTROL_PLANE_PORTconfiguration toconfig.tswith validation (1-65535 range)index.tsto use configurable port with error handling for port conflictssecurity-service.tsto dynamically protect the configured control plane portSDK (
packages/sandbox/):controlPlanePortproperty toSandboxclassSANDBOX_CONTROL_PLANE_PORTfrom environmentSandboxClientinitialization to use configurable portdeterminePortmethod to route control plane requests to configured portDocumentation:
CLAUDE.mdwith configuration instructions and examplesTesting:
Usage:
In Dockerfile:
ENV SANDBOX_CONTROL_PLANE_PORT=3001In Worker environment:
Error Handling:
When a port conflict occurs, the container now provides clear error messages:
Link to Devin run: https://app.devin.ai/sessions/001d37fe2d324d48bbd3a27a884fd98e
Requested by: @ghostwriternr