Port Forwarding
Expose services running inside a sandbox.
Sandboxes are isolated by default: a service listening inside one is not reachable from the internet until you expose it. Daytona gives you three ways to do that, each suited to a different job. Declared ports set up raw TCP/UDP forwarding at create time; preview endpoints give any in-sandbox HTTP port a stable URL — public or token-protected — that you can create and revoke at any time; and SSH tunnels cover quick, private, ad hoc access.
Declaring ports at create
If you know a sandbox will serve traffic, declare its ports when you create it. Daytona assigns a public mapping for each declared port and returns it in the sandbox's port_map field.
You choose the in-sandbox port (vm_port) and protocol; the platform chooses the public side of the mapping. Fetch the sandbox (GET /vms/:id) and read port_map to learn where to connect.
Preview endpoints
Preview endpoints expose an in-sandbox HTTP port on a stable URL of the form https://<port>-<sandbox-id>.<preview-domain>/, without any create-time declaration. Each endpoint is either private (the default — a credential is required) or public (anyone with the URL can reach it), and you can flip that flag at any time.
The default is fail-closed: a port nobody exposed is not reachable at all, and a freshly exposed one requires a credential unless you explicitly opt into public.
Exposing a port
expose_port / exposePort is idempotent: exposing an already-exposed port returns the existing endpoint, adjusting its visibility if it differs from what you asked for. The raw REST call instead returns 409 Conflict on a duplicate.
Accessing a private endpoint
get_preview_link / getPreviewLink returns the endpoint's URL together with a preview token. Send the token in the x-daytona-preview-token header (a project API key or the sandbox's access token also works). The first call registers the port as private if it wasn't exposed yet; repeated calls return the same URL and token.
Managing endpoints
Endpoints also appear in the Preview tab of the sandbox page in the dashboard.
End-to-end example
Run a web server inside a sandbox and reach it from outside:
Ad hoc access: SSH tunnels
For quick, private access during development — no endpoint, no declared port — tunnel over SSH:
See also
- SSH Access — tunnels and interactive shells.
- Creating Sandboxes → Parameters — the full create-time surface, including
ports.