exposePort() method provides a public HTTPS URL that maps directly to a specific port running inside your sandbox container. Fermion automatically supports ports 3000, 1337, and 1338, allowing you to host web servers, APIs, or other services securely and access them from anywhere.
When you start a server inside your sandbox, using commands like node server.js or npm run dev, you can call exposePort(port) to instantly retrieve a URL in the format https://{subdomain}-{port}.run-code.com. This enables you to preview, test, and share live services running within your sandbox without any manual networking setup or tunneling.
The returned URLs are ephemeral, meaning they last only for the sandbox’s lifetime. Each new session generates new subdomains for security and isolatio
exposePort(port)
Description:
Returns the public HTTPS URL for a specific port in the sandbox. The sandbox automatically exposes ports 3000, 1337, and 1338 publicly.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| port | 3000 | 1337 | 1338 | Yes | Port number (must be one of these three) |
Promise<string> - Public HTTPS URL (format: https://{subdomain}-{port}.run-code.com)
Example:
Error: "No container found"- Must callcreate()orfromSnippet()first- TypeScript error if port is not 3000, 1337, or 1338
- URLs are available immediately, even before a server starts
- Accessing URL before server starts will show connection error
- HTTPS is automatic - no certificate setup needed
- URLs are stable during sandbox lifetime
- URLs change on reconnect to same snippet
- Wait a moment after starting server before accessing URL
- Add error handling when fetching URLs
- Use health check endpoints to verify server is ready
