Skip to content

Forward a host port to a port on the sandbox’s 127.0.0.1, or change the forward it has.

sandbox.ports.add(hostPort: number, guestPort: number, options?: { public?: boolean }): Promise<Port>

Examples

const forward = await sandbox.ports.add(9000, 8000);
console.log(forward.listening, forward.reachableOn);
await sandbox.ports.add(9000, 8000, { public: true });

Arguments

TypeScript Python Description
hostPort host_port port on the host
guestPort guest_port port the program in the sandbox listens on, on 127.0.0.1

Options

TypeScript Python Description
public public listen on 0.0.0.0, every interface of the host, not 127.0.0.1

A running sandbox takes the forward at once; any other from its next start. The forward survives a stop and a start. To forward ports from the first start, pass ports to shard.create.

Add the same host port again to change its guest port or its visibility. public is the only way to listen beyond this host; it opens the port to every network the host is on.

The result

A Port holds the sandbox ID and name, the host and guest ports, public, address, listening, error and the addresses a client reaches it on (reachableOn, or reachable_on in Python). listening is false while the sandbox is not running or the host refuses the port, and error says why.

List the forwards of a sandbox, in host port order.

sandbox.ports.list(): Promise<Port[]>

Examples

for (const port of await sandbox.ports.list()) console.log(port.hostPort, port.guestPort, port.listening);

End a forward and the connections it carries.

sandbox.ports.remove(hostPort: number): Promise<void>

Examples

await sandbox.ports.remove(9000);

List the forwards of every sandbox, in host port order.

shard.ports(): Promise<Port[]>

Examples

for (const port of await shard.ports()) console.log(port.sandboxName, port.hostPort);

For the whole flow, see Expose a port of a sandbox.