devsandbox 0.11.0

Manage devcontainer-style sandboxes on docker, podman, or Apple container — many throwaway instances per repo from one TOML config.
---
title: Port forwarding on demand
description: Open a sandbox's dev server or database from your host, without restarting anything.
order: 5
icon: plug
tags: [networking, services]
related: [services, parallel-agents, port-a-devcontainer]
---

## The problem

An agent started a dev server on port 3000 in instance `api`, and you want it in your browser. `-p` has to be decided at create time and collides with the next instance. `devsandbox port` forwards a port on demand, with nothing published.

## Try it

```bash
devsandbox port api 3000                        # http://localhost:3000
devsandbox port api 8080:3000                   # host :8080 to api's :3000
devsandbox port api --service postgres 5432     # a service api uses
devsandbox port my-server/web 3000              # an instance on another machine
```

`devsandbox port` forwards until Ctrl-C. In the dashboard, `p` adds a forward that the host daemon keeps until you stop it. [`forwardPorts`](/docs/config#implemented-devcontainer-properties) `= [3000]` forwards a port whenever the instance runs.

## How it works

- Connections go through the in-container helper, so a server on the container's `127.0.0.1` is reachable.
- A bare port taken on the host falls back to the next free one, and the printed line says which.
- Unix hosts, TCP only.