# Expose a port

> Give a port inside the sandbox an HTTPS URL, to reach a web server or API you started in it. The service must listen on 0.0.0.0. A sandbox exposes at most 20 ports.

`POST https://api.zavu.dev/v1/sandboxes/{sandboxId}/ports`

Give a port inside the sandbox an HTTPS URL, to reach a web server or API you started in it. The service must listen on `0.0.0.0`. A sandbox exposes at most 20 ports.

## Parameters

- `sandboxId` (path, string, required): Sandbox ID.

## Body

- `port` (integer, required): Port your service listens on inside the machine.
- `public` (boolean): `false` returns a URL with an access token in its query string: anyone holding the full URL can open it, so treat it as a secret. Opened in a browser, the token moves into a cookie for that host and leaves the address bar, so the page's own links, assets and WebSockets work. Other clients send it as `?_token=` on every request. `true` returns a URL anyone can open. Calling again with a different value changes it for the same URL.

## Responses

### 200

The URL.

- `port` (object, required)
  - `port` (integer, required)
  - `url` (string<uri>, required): HTTPS URL on `zavu.run` that reaches the port, WebSockets included. Calling this again for the same port returns the same URL. It keeps working across a stop and resume; while the sandbox is stopped it answers `503`, and once the sandbox is deleted it answers `404`.
  - `public` (boolean, required)

### 400

Invalid port.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 401

Unauthorized.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 404

Sandbox not found, or it belongs to another project.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 409

`sandbox_not_running`: the sandbox is stopped, stopping, failed or deleted; resume it first. `sandbox_not_ready`: it is still starting and did not become ready in time; retry. `port_limit_reached`: it already exposes 20 ports.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 503

`sandbox_unavailable`: ports cannot be exposed right now; retry shortly.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

## Example

```bash
curl -X POST "https://api.zavu.dev/v1/sandboxes/sandbox_abc123/ports" \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "port": 3000
}'
```

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({ apiKey: process.env.ZAVUDEV_API_KEY });

const result = await zavu.sandboxes.ports.expose("sandbox_abc123", {
  port: 3000,
});

console.log(result);
```
