---
title: "Ports"
description: "Reach a server that runs in a sandbox."
---

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

# Ports

A port makes a server in a sandbox reachable from outside it. Nothing in a sandbox is reachable until you create a port for it.

## Access

A port is private unless you make it public.

- **Private** (the default): a request needs your API key in the `Authorization` header, or a signed link.
- **Public**: anyone with the address can reach it.

A signed link works without a credential until it expires. Create one with `generateSignedUri` and pass `expiresIn` in seconds. Use it to share a running app with someone who has no API key.

Change the access of an existing port with `update`. Delete the port to make the server unreachable again; the process keeps running.

## Addresses

Each port gets its own host in `uri`. The host carries an id that cannot be guessed and is not made from your sandbox or project names. A port number with no port resource is not reachable, even if a server listens on it.

You can also create ports when you create the sandbox, with `ports` in the create call.

## All ports

A sandbox can serve all of its ports without a port resource for each. Every port a process listens on is then reachable at its own host, private or public as the sandbox says. It is off by default. Use it for an agent that starts servers on ports you do not know in advance.

## What passes through

The proxy in front of a port forwards your request as it is:

- Your own `Authorization` header and cookies reach your server unchanged.
- WebSocket upgrades and streamed bodies work.
- The proxy sets no body size limit of its own.

When the proxy itself returns an error, the response says that it came from Sutra and not from your server.

:::note[Today]
Today a port is opened with a `preview binding` call: `openPreviewBinding` in TypeScript, `open_preview_binding` in Python, `anchor sandbox preview open` in the CLI. A new sandbox has no open port.

A port is private unless the call writes `accessMode: "PUBLIC"` (`--access-mode public` in the CLI). A request to a private port needs your API key as `Authorization: ApiKey <key>`, so a browser cannot open it. Signed links are not available yet. A link does not expire: it works until the port is closed or the sandbox stops.

A port's host has the form `3000-<sandbox id>-<key>-<hash>.preview.jgcp.mistrivedev.com`, made from the sandbox id, the key you chose and the port. Read it from `generatedHost` instead of building it. A host you choose yourself, with `anchorSubdomain`, cannot start with digits and a hyphen.

A port without an open `preview binding` answers `404`. To serve all ports, open one port with `allPorts: true` (`--all-ports` in the CLI): every port is then served at that port's host with its own number in front, such as `5173-<sandbox id>-<key>-<hash>`. All of them are public only when that call writes `PUBLIC`. A sandbox can have one such port.

`getPreviewLink(port)` (`get_preview_link` in Python) returns the link of an open port, and `NOT_FOUND` for a port that is not open. Close a port with `closePreviewBinding` or `anchor sandbox preview close <sandbox>/<key>`.
:::

Source: https://docs.jgcp.mistrivedev.com/sandboxes/ports/index.mdx
