> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fermion.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Expose ports from Sandbox for a public HTTPS URL

> Expose a sandbox port publicly over HTTPS and access live web services running inside the container.

The `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.

### `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) |

**Returns:**
`Promise<string>` - Public HTTPS URL (format: `https://{subdomain}-{port}.run-code.com`)

**Example:**

```typescript theme={null}
// Start a server
await sandbox.writeFile({
	path: '/home/damner/server.js',
	content: `
    const http = require('http');
    http.createServer((req, res) => {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello from Fermion!');
    }).listen(3000, () => {
      console.log('Server running on port 3000');
    });
  `
})

// Run server in background (~/ works in commands, shell expands it)
sandbox.runStreamingCommand({
	cmd: 'node',
	args: ['~/server.js'],
	onStdout: data => console.log(data.trim())
})

// Wait a moment for server to start
await new Promise(r => setTimeout(r, 2000))

// Get public URL
const url = await sandbox.exposePort(3000)
console.log('Access your server at:', url)
// Output: https://abc123xyz-3000.run-code.com

await new Promise(r => setTimeout(r, 30000)) // Wait for 30 seconds
```
