Web apps and ports
When a program listens on a port of a machine (a web app, a database, an API), Bodylet gives you three ways to reach it. None of them opens a port on the machine or on your router: everything goes through the machine's own connection to Bodylet.
Which one to use#
| You want to | Use |
|---|---|
| Show a web app to a person of your account, in a browser | A preview |
| Use a tool of your own computer with a service of the machine: a database client, SSH, a remote desktop, a debugger | A forward |
| Let a program call a web service of the machine: a script, a webhook you configure, an MCP client | An exposure with --token |
| Preview | Forward | Exposure | |
|---|---|---|---|
| Who gets in | People signed in to your dashboard | You, or an agent, on the computer that runs the forward | Programs with a key, or people signed in to your dashboard |
| What it carries | Web pages | Any TCP connection | Web requests |
| Where you connect | A private https:// address | 127.0.0.1 on your own computer | An https:// address |
| On the agent's token | Open previews, when an agent opens it | Forward ports | Open previews |
| On the machine | The owner opens the port to previews | The owner opens the port to forwards | The owner opens the port to previews |
All three reach only the machine's own loopback address (127.0.0.1) and ports from 1024 to 65535. Ports below 1024 are never reachable, so SSH on port 22 or a web server on port 80 cannot be reached this way: start them on a port of 1024 or more.
Previews#
What happens. The agent starts the server as a job on the machine, listening on 127.0.0.1, and checks that it answers. Then it opens a preview and gives you its address, or you open it yourself: in the dashboard, open the job (from Jobs, or from the machine's page) and, under Ports, choose Open a preview.
The address looks like https://k3v9x2m7q4r8.<preview domain>/. It opens in a browser signed in to your Bodylet account, on a phone too. Your browser never connects to the machine.
- Only people signed in to your account can load it. An agent or a script cannot: a token gets no page there. To check the app, an agent makes the request on the machine itself.
- The address is not a secret, and it says nothing about the machine. It holds a random key only, never the machine's name or the port. It is written in public certificate logs the first time it is opened.
- The Previews page lists open previews. Close ends one at once, in every tab. A preview opened with
bodylet preview openends by itself after 8 hours, unless--ttlsays otherwise.
With the command line:
bodylet preview open build-box --port 5173
bodylet preview list
bodylet preview close <id>It needs: the port opened to previews by the machine's owner, and Open previews on the token when an agent opens the preview itself.
bodylet policy allow ports.preview 3000-9999 # by the machine's ownerForwards#
A forward lets any program on your computer talk to a port of a machine as if it ran on your computer.
bodylet forward build-box:5432 --local 15432Local: 127.0.0.1:15432
Remote: port 5432 of build-box
Forward: fwd_...
Ends: ... at the latest
Connect a program to 127.0.0.1:15432. Press Ctrl-C to stop.Then, in another terminal:
psql -h 127.0.0.1 -p 15432 -U ana mydbSSH works the same way, with an SSH server listening on a port of 1024 or more on the machine:
bodylet forward build-box:2222
ssh -p 2222 ana@127.0.0.1- Nothing is public. The forward listens on your computer only, and each connection carries the token of your
bodyletcommand. - Your port. By default the same number as on the machine when it is free here, otherwise any free port; the command prints which.
--local PORTchooses it. - How long. Until you press Ctrl-C, which prints what went through. Otherwise it ends after one hour (
--ttl, up to 24 hours). A connection that carries nothing for an hour is closed. - Stay on loopback.
--bindwith another address than127.0.0.1lets other computers of your network use the forward, with your token. The command warns you. - A token keeps up to 8 forwards open, each with up to 16 connections at once.
It needs: Forward ports on the token, and the port opened to forwards by the machine's owner. Forwards are separate from previews: opening a port to previews does not open it to forwards.
bodylet policy allow ports.forward # every port from 1024
bodylet policy allow ports.forward 5432 8000-8100 # only these portsThe program on the machine must listen on 127.0.0.1 (or on every address), under the same account as Bodylet. A server of another account (a system service, another user) is refused unless the owner allows it with bodylet policy allow forward.other_accounts.
Exposures#
An exposure gives a port of a machine an https:// address that programs can call.
bodylet expose build-box --port 8080 --token --name backofficeChoose who gets in:
| Option | Who gets in |
|---|---|
--private (the default) | People signed in to your dashboard, in a browser |
--token | Programs that send the exposure's secret, or an agent token of your fleet that sees the machine. People of your account, in a browser, too |
With --token, the command prints the secret once:
Secret: ...
It is shown once: keep it now.A program sends it in the header Bodylet-Exposure-Secret, or as Authorization: Bearer:
curl -sS -H "Bodylet-Exposure-Secret: $SECRET" https://backoffice.<preview domain>/The secret never reaches your program, and neither does a Bodylet token. Keep the secret in your program's secret store. If you lose it, close the exposure and expose again: you get a new one.
- A stable address.
--name backofficegiveshttps://backoffice.<preview domain>/, the same address each time you expose under that name. A name has 3 to 32 lowercase letters, digits and single hyphens. It stays yours until you give it back withbodylet unexpose backoffice --release-name. Like any address, it becomes public in certificate logs once used. - How long. 8 hours unless you give
--ttl. - Without a machine name,
bodylet expose --port 3000exposes the machine the command runs on. bodylet exposureslists your exposures with the requests they served.bodylet unexpose ID(or the name) closes one at once.
It needs: Open previews on the token, and the port opened to previews by the machine's owner.