You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed critical runtime errors in code examples: missing exports,
incorrect API signatures, and missing required parameters.
Added documentation for custom startup scripts and local development
warnings for port exposure requirements.
-`hostname` - Your Worker's domain name (e.g., `'example.com'`). Required to construct preview URLs with wildcard subdomains like `https://8080-sandbox-abc123.example.com`. Cannot be a `.workers.dev` domain as it doesn't support wildcard DNS patterns.
31
+
-`name` - Friendly name for the port (optional)
31
32
32
33
**Returns**: `Promise<ExposePortResponse>` with `port`, `exposedAt` (preview URL), `name`
When using `wrangler dev`, you must add `EXPOSE` directives to your Dockerfile for each port. See [Expose Services guide](/sandbox/guides/expose-services/#local-development) for details.
When using `wrangler dev`, you must add `EXPOSE` directives to your Dockerfile for each port. See [Local development with ports](/sandbox/guides/expose-services/#local-development).
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/concepts/preview-urls.mdx
+24-12Lines changed: 24 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,20 +12,23 @@ Preview URLs work in local development without configuration. For production, yo
12
12
Preview URLs provide public HTTPS access to services running inside sandboxes. When you expose a port, you get a unique URL that proxies requests to your service.
Preview URLs support WebSocket connections. When a WebSocket upgrade request hits an exposed port, the routing layer automatically handles the connection handshake.
89
97
90
98
```typescript
99
+
// Extract hostname from request
100
+
const { hostname } =newURL(request.url);
101
+
91
102
// Start a WebSocket server
92
103
awaitsandbox.startProcess("bun run ws-server.ts 8080");
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/configuration/dockerfile.mdx
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,43 @@ Update `wrangler.jsonc` to reference your Dockerfile:
66
66
67
67
When you run `wrangler dev` or `wrangler deploy`, Wrangler automatically builds your Docker image and pushes it to Cloudflare's container registry. You don't need to manually build or publish images.
68
68
69
+
## Custom startup scripts
70
+
71
+
Run services automatically when the container starts by creating a custom startup script:
72
+
73
+
```dockerfile title="Dockerfile"
74
+
FROM docker.io/cloudflare/sandbox:0.3.3
75
+
76
+
COPY my-app.js /workspace/my-app.js
77
+
COPY startup.sh /workspace/startup.sh
78
+
CMD ["/workspace/startup.sh"]
79
+
```
80
+
81
+
```bash title="startup.sh"
82
+
#!/bin/bash
83
+
84
+
# Start your services in the background
85
+
node /workspace/my-app.js &
86
+
87
+
# Must end with this command
88
+
exec bun /container-server/dist/index.js
89
+
```
90
+
91
+
Your startup script must end with `exec bun /container-server/dist/index.js` to start the SDK's control plane.
92
+
93
+
### Multiple services
94
+
95
+
```bash title="startup.sh"
96
+
#!/bin/bash
97
+
98
+
redis-server --daemonize yes
99
+
until redis-cli ping;do sleep 1;done
100
+
101
+
node /workspace/api-server.js &
102
+
103
+
exec bun /container-server/dist/index.js
104
+
```
105
+
69
106
## Related resources
70
107
71
108
-[Image Management](/containers/platform-details/image-management/) - Building and pushing images to Cloudflare\'s registry
0 commit comments