Ports
Expose services running in your sandbox via public preview URLs. See Preview URLs concept for details.
Expose a port and get a preview URL.
const response = await sandbox.exposePort(port: number, options?: ExposePortOptions): Promise<ExposePortResponse>
Parameters:
port
- Port number to expose (1024-65535)options
(optional):name
- Friendly name for the port
Returns: Promise<ExposePortResponse>
with port
, exposedAt
(preview URL), name
await sandbox.startProcess("python -m http.server 8000");const exposed = await sandbox.exposePort(8000);
console.log("Available at:", exposed.exposedAt);// https://abc123-8000.sandbox.workers.dev
// Multiple services with namesawait sandbox.startProcess("node api.js");const api = await sandbox.exposePort(3000, { name: "api" });
await sandbox.startProcess("npm run dev");const frontend = await sandbox.exposePort(5173, { name: "frontend" });
await sandbox.startProcess('python -m http.server 8000');const exposed = await sandbox.exposePort(8000);
console.log('Available at:', exposed.exposedAt);// https://abc123-8000.sandbox.workers.dev
// Multiple services with namesawait sandbox.startProcess('node api.js');const api = await sandbox.exposePort(3000, { name: 'api' });
await sandbox.startProcess('npm run dev');const frontend = await sandbox.exposePort(5173, { name: 'frontend' });
Remove an exposed port and close its preview URL.
await sandbox.unexposePort(port: number): Promise<void>
Parameters:
port
- Port number to unexpose
await sandbox.unexposePort(8000);
await sandbox.unexposePort(8000);
Get information about all currently exposed ports.
const response = await sandbox.getExposedPorts(): Promise<GetExposedPortsResponse>
Returns: Promise<GetExposedPortsResponse>
with ports
array (containing port
, exposedAt
, name
)
const { ports } = await sandbox.getExposedPorts();
for (const port of ports) { console.log(`${port.name || port.port}: ${port.exposedAt}`);}
const { ports } = await sandbox.getExposedPorts();
for (const port of ports) { console.log(`${port.name || port.port}: ${port.exposedAt}`);}
- Preview URLs concept - How preview URLs work
- Commands API - Start background processes
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-