Skip to content

Install the agent

Run the install command, give it the join token, and check that the agent is running.

On this page

The install command

Create it in the app: Provide, Hosts, Add a host, then Create install command. It looks like this:

Shell
curl -fsSLo install.sh https://get.legion.ambient.xyz/legion-agent/v0.14.1/install.sh && echo "1f601d9d60646908fa2f0285ea2bdd956ce99daeef73ec7bbde012968e56623e  install.sh" | sha256sum -c - && sudo bash install.sh

It downloads the install script for the current agent release, checks the script's SHA-256, and only then runs it as root. You can read the script before you run it.

The join token

The app shows a join token next to the command. Press Show token to see it.

  • It works for one machine, once, for 24 hours.

  • The installer asks for it at a hidden prompt. Paste it there. The token never goes on the command line, where other users could see it.

  • If it expires or you lose it, create a new command.

Options

Add these to the end of the command. For the token, pick one instead of the hidden prompt, under No prompt, or running it from a script?:

Options
OptionWhat it does
--token-file <path>Reads the token from a file only its owner can read, instead of the prompt.
--token-stdin < <path>Reads the token from standard input.
--no-userns-remapLeaves Docker's user namespaces alone. A host without them is not rented from Nov 25, 2026 at 15:00 UTC, unless the agent turns them on later. See User namespaces.

The installer also sets up the disk rentals use on its own; see Add your first host for how it chooses and the flags that take over that choice.

Finish disk setup

If the installer set up a disk, run this once the host shows Online in the app:

Shell
sudo legion-agent setup-disk --finish

Skip this if the installer skipped disk setup, by flag or because it couldn't set one up.

User namespaces

Legion requires Docker's userns-remap on every host, so root in a rental is an unprivileged user ID on your machine instead of root. The installer turns it on, on every run, not only the first, whenever Docker is not remapped and the host has no rentals:

  • No other containers or volumes on Docker: it switches with no prompt. It restarts Docker once and checks, in a test container, that root is remapped and the GPUs work. If a check fails it puts Docker back as it was and prints a warning. The install goes on either way.

  • Other containers or volumes on Docker: switching restarts Docker and hides them from Docker until you turn it off. An interactive install asks once: "Legion needs Docker user-namespace isolation; enabling it restarts Docker and hides your existing containers and images from Docker until it's turned off. Enable now? [Y/n]". The default is yes. A non-interactive install leaves Docker alone and prints why.

If the installer leaves it off, the agent turns it on by itself once Docker is idle: the host has no rentals and no containers or volumes that are not Legion's. While it switches, the host takes no new rentals, for the few minutes it needs. If it fails, the agent puts Docker back as it was and tries again after 6 hours, or after an agent upgrade.

The host's page in the app says where this stands, in its Isolation section. See User-namespace isolation for the states, why, from when, and the manual command.

To see whether it is on:

Shell
docker info --format '{{.SecurityOptions}}'

The output lists name=userns when it is on. legion-agent status also prints the state and the next step.

You only need the command yourself when the agent can't switch, for example because Docker runs other containers that you want to keep until you stop them. Run it while the host has no rentals:

Shell
sudo legion-agent enable-userns

It runs the same checks and changes nothing if they fail. It refuses while rentals or containers are on the host. With --force it switches anyway, and those rentals can no longer read or write the files they already have. Docker downloads images again after the switch.

To turn it off again, with no rentals on the host, remove "userns-remap" from /etc/docker/daemon.json, then run sudo systemctl restart docker and sudo systemctl restart legion-agent. The agent turns it on again when the host is idle, unless you take the host out of the market.

Check the agent

Shell
systemctl status legion-agent
legion-agent status

In the app, the host shows Online once the agent has reported in within the last 90 seconds.

A new host is also benchmarked once before renters can see it. It is queued as soon as you save a price and turn on Show in the market, and you can watch it live: see First benchmark.

To watch the agent from your own Prometheus and get alerts, see Monitoring with Prometheus.

If the command fails

It prints the reason in your terminal. Fix it and run a new command: each one works for one machine.