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

# Expose ports

> Publish HTTP ports of a running Devbox on shareable devbox.so URLs.

Use `devbox.exposedPorts` to publish an HTTP server running on a Devbox at a `devbox.so` URL, and to list and remove the URLs a Devbox exposes.

<Info>
  Exposed port operations start a stopped Devbox automatically.
</Info>

See [Shareable URLs](/docs/devbox/url) for how `devbox.so` URLs work and who can open them.

## `exposedPorts.create()`

Use `exposedPorts.create()` to expose an HTTP port and get its URL.

<h3 id="exposedports-create-example">
  Example
</h3>

```typescript {2-3} theme={null}
const devbox = await client.devboxes.get("sdk-example");
const port = await devbox.exposedPorts.create({ name: "web", number: 3000 });
console.log(port.url);
```

<h3 id="exposedports-create-api-reference">
  API reference
</h3>

```typescript theme={null}
exposedPorts.create(input: ExposedPort, options?: OperationOptions): Promise<ExposedPortInfo>
```

<h4 id="exposedports-create-arguments-and-options">
  Arguments and options
</h4>

<ResponseField name="input" type="ExposedPort" required>
  The port to expose.

  <Expandable title="properties" defaultOpen>
    <ResponseField name="number" type="number" required>
      The port number. It must be an integer between `1` and `65535`.
    </ResponseField>

    <ResponseField name="name" type="string">
      A name for the port, which you can use to look it up later. When set, it must not be empty or contain only whitespace.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="options" type="OperationOptions">
  Supports `signal` and `timeoutMs`. See [Handle errors and timeouts](/docs/reference/typescript-sdk/devbox/errors#operationoptions).
</ResponseField>

<h4 id="exposedports-create-return-value">
  Return value
</h4>

`exposedPorts.create()` resolves with the [`ExposedPortInfo`](#exposedportinfo) for the new port, including its `url`. It throws a `RangeError` for an invalid port number and a `TypeError` for an empty name, before contacting the Devbox.

***

## `exposedPorts.get()`

Use `exposedPorts.get()` to look up one exposed port by ID, name, or number.

<h3 id="exposedports-get-example">
  Example
</h3>

```typescript {2-3} theme={null}
const devbox = await client.devboxes.get("sdk-example");
const port = await devbox.exposedPorts.get({ name: "web" });
console.log(port.url);
```

<h3 id="exposedports-get-api-reference">
  API reference
</h3>

```typescript theme={null}
exposedPorts.get(selector: ExposedPortSelector, options?: OperationOptions): Promise<ExposedPortInfo>
```

<h4 id="exposedports-get-arguments-and-options">
  Arguments and options
</h4>

<ResponseField name="selector" type="ExposedPortSelector" required>
  The port to look up. See [`ExposedPortSelector`](#exposedportselector).
</ResponseField>

<ResponseField name="options" type="OperationOptions">
  Supports `signal` and `timeoutMs`. See [Handle errors and timeouts](/docs/reference/typescript-sdk/devbox/errors#operationoptions).
</ResponseField>

<h4 id="exposedports-get-return-value">
  Return value
</h4>

`exposedPorts.get()` resolves with the matching [`ExposedPortInfo`](#exposedportinfo). It lists the Devbox's exposed ports and selects the match on the client. It rejects with `ExposedPortNotFoundError` when no port matches.

***

## `exposedPorts.list()`

Use `exposedPorts.list()` to list the HTTP ports a Devbox exposes.

<h3 id="exposedports-list-example">
  Example
</h3>

```typescript {2-5} theme={null}
const devbox = await client.devboxes.get("sdk-example");
const ports = await devbox.exposedPorts.list();
for (const port of ports) {
  console.log(port.number, port.url);
}
```

<h3 id="exposedports-list-api-reference">
  API reference
</h3>

```typescript theme={null}
exposedPorts.list(options?: OperationOptions): Promise<ExposedPortInfo[]>
```

<h4 id="exposedports-list-arguments-and-options">
  Arguments and options
</h4>

<ResponseField name="options" type="OperationOptions">
  Supports `signal` and `timeoutMs`. See [Handle errors and timeouts](/docs/reference/typescript-sdk/devbox/errors#operationoptions).
</ResponseField>

<h4 id="exposedports-list-return-value">
  Return value
</h4>

`exposedPorts.list()` resolves with an [`ExposedPortInfo`](#exposedportinfo) for each HTTP port the Devbox agent reports, including ports owned by Namespace. Check `owner` to distinguish them. Port forwards are not included.

***

## `exposedPorts.delete()`

Use `exposedPorts.delete()` to stop exposing a port. The process listening on the port keeps running.

<h3 id="exposedports-delete-example">
  Example
</h3>

```typescript {2} theme={null}
const devbox = await client.devboxes.get("sdk-example");
await devbox.exposedPorts.delete({ number: 3000 });
```

<h3 id="exposedports-delete-api-reference">
  API reference
</h3>

```typescript theme={null}
exposedPorts.delete(selector: ExposedPortSelector, options?: OperationOptions): Promise<void>
```

<h4 id="exposedports-delete-arguments-and-options">
  Arguments and options
</h4>

<ResponseField name="selector" type="ExposedPortSelector" required>
  The port to stop exposing. See [`ExposedPortSelector`](#exposedportselector).
</ResponseField>

<ResponseField name="options" type="OperationOptions">
  Supports `signal` and `timeoutMs`. See [Handle errors and timeouts](/docs/reference/typescript-sdk/devbox/errors#operationoptions).
</ResponseField>

<h4 id="exposedports-delete-return-value">
  Return value
</h4>

`exposedPorts.delete()` resolves when the port is no longer exposed. It rejects with `ExposedPortNotFoundError` when no port matches the selector.

***

## Exposed port types

### `ExposedPortInfo`

```typescript theme={null}
interface ExposedPortInfo {
  id: string;
  name?: string;
  number: number;
  url: string;
  owner: "user" | "namespace" | "unknown";
}
```

<ResponseField name="id" type="string" required>
  The port ID.
</ResponseField>

<ResponseField name="name" type="string">
  The port name, when one is set.
</ResponseField>

<ResponseField name="number" type="number" required>
  The port number.
</ResponseField>

<ResponseField name="url" type="string" required>
  The `devbox.so` URL that serves the port.
</ResponseField>

<ResponseField name="owner" type="&#x22;user&#x22; | &#x22;namespace&#x22; | &#x22;unknown&#x22;" required>
  Who manages the port.
</ResponseField>

### `ExposedPortSelector`

Selects a port by exactly one of `id`, `name`, or `number`. Passing none or more than one throws a `TypeError`.

```typescript theme={null}
type ExposedPortSelector =
  | { id: string }
  | { name: string }
  | { number: number };
```

## Related documentation

<Columns cols={3}>
  <Card title="Shareable URLs" icon="globe" href="/docs/devbox/url">
    Learn how devbox.so URLs work.
  </Card>

  <Card title="Run services" icon="server" href="/docs/reference/typescript-sdk/devbox/services">
    Supervise the servers you expose.
  </Card>

  <Card title="Handle errors and timeouts" icon="triangle-alert" href="/docs/reference/typescript-sdk/devbox/errors">
    Cancel operations and handle SDK failures.
  </Card>
</Columns>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.