Conversation
|
There was a problem hiding this comment.
OpenCode Review
This is a well-structured WebSocket tunneling example that demonstrates key sandbox features. The implementation follows repository patterns and serves as useful documentation.
What it accomplishes:
- Shows how to expose WebSocket services via
exposePort()andproxyToSandbox() - Demonstrates the preview URL pattern for connecting to sandbox services
- Provides a working ping/pong WebSocket implementation using Bun
Minor issues to address:
Duplicate HTML files: Both public/index.html and public/template.html are identical. Only one is needed - the template.html appears unused and should be removed.
Port exposure timing: The code calls exposePort() before starting the server process. While this works, it's more conventional to start the process first, then expose the port. Consider reordering for clarity:
await sandbox.startProcess('bun /app/server.js', { processId: 'ws-server' });
await sandbox.waitForPort({ portToCheck: WS_PORT });
const p = await sandbox.exposePort(WS_PORT, { hostname: url.host });Documentation consistency: The README mentions both "buttons" (connect/disconnect and send ping) but only describes two. Consider clarifying that there are two buttons total.
The core implementation is solid and follows the documented patterns correctly. Nice work demonstrating the sandbox WebSocket capabilities!
| @@ -0,0 +1,208 @@ | |||
| <!doctype html> | |||
There was a problem hiding this comment.
This file is identical to index.html. Since it's unused, it should be removed.
| .getExposedPorts(url.host) | ||
| .then((ports) => ports.find((p) => p.port === WS_PORT)); | ||
| if (!port) { | ||
| const p = await sandbox.exposePort(WS_PORT, { hostname: url.host }); |
There was a problem hiding this comment.
Consider moving exposePort() after startProcess() and waitForPort() for clearer flow - expose the port only after the service is ready.
commit: |
🐳 Docker Images PublishedDefault: FROM cloudflare/sandbox:0.0.0-pr-431-0748868With Python: FROM cloudflare/sandbox:0.0.0-pr-431-0748868-pythonWith OpenCode: FROM cloudflare/sandbox:0.0.0-pr-431-0748868-opencodeVersion: Use the 📦 Standalone BinaryFor arbitrary Dockerfiles: COPY --from=cloudflare/sandbox:0.0.0-pr-431-0748868 /container-server/sandbox /sandbox
ENTRYPOINT ["/sandbox"]Download via GitHub CLI: gh run download 22454841225 -n sandbox-binaryExtract from Docker: docker run --rm cloudflare/sandbox:0.0.0-pr-431-0748868 cat /container-server/sandbox > sandbox && chmod +x sandbox |
d685081 to
5749cf7
Compare
This example sets up a Bun webserver with a simple WebSocket client plus a basic browser client for connecting to the server via a worker and sending ping/pong messages back and forth. This demonstrates how to start a webserver and proxy the requests through to the sandbox. The browser client is a single HTML page served via an assets binding to serve the HTML file.
5749cf7 to
d240df7
Compare
This example sets up a Bun webserver with a simple WebSocket client
plus a basic browser client for connecting to the server via a worker
and sending ping/pong messages back and forth.
This demonstrates how to start a webserver and proxy the requests
through to the sandbox.
The browser client is a single HTML page served via an assets binding
to serve the HTML file.