Skip to content
Bodylet AIBodylet AI
All pages

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 toUse
Show a web app to a person of your account, in a browserA preview
Use a tool of your own computer with a service of the machine: a database client, SSH, a remote desktop, a debuggerA forward
Let a program call a web service of the machine: a script, a webhook you configure, an MCP clientAn exposure with --token
PreviewForwardExposure
Who gets inPeople signed in to your dashboardYou, or an agent, on the computer that runs the forwardPrograms with a key, or people signed in to your dashboard
What it carriesWeb pagesAny TCP connectionWeb requests
Where you connectA private https:// address127.0.0.1 on your own computerAn https:// address
On the agent's tokenOpen previews, when an agent opens itForward portsOpen previews
On the machineThe owner opens the port to previewsThe owner opens the port to forwardsThe 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 open ends by itself after 8 hours, unless --ttl says otherwise.

With the command line:

Terminal
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.

Terminal
bodylet policy allow ports.preview 3000-9999   # by the machine's owner

Forwards#

A forward lets any program on your computer talk to a port of a machine as if it ran on your computer.

Terminal
bodylet forward build-box:5432 --local 15432
Local:    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:

Terminal
psql -h 127.0.0.1 -p 15432 -U ana mydb

SSH works the same way, with an SSH server listening on a port of 1024 or more on the machine:

Terminal
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 bodylet command.
  • 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 PORT chooses 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. --bind with another address than 127.0.0.1 lets 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.

Terminal
bodylet policy allow ports.forward                 # every port from 1024
bodylet policy allow ports.forward 5432 8000-8100  # only these ports

The 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.

Terminal
bodylet expose build-box --port 8080 --token --name backoffice

Choose who gets in:

OptionWho gets in
--private (the default)People signed in to your dashboard, in a browser
--tokenPrograms 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:

Terminal
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 backoffice gives https://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 with bodylet 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 3000 exposes the machine the command runs on.
  • bodylet exposures lists 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.