# Images and the runtime

> Choose a starter image or bring your own, and see what Legion adds to every rental.

Source: https://legion.ambient.xyz/docs/renting/images

Every rental runs one container image. Use one of Legion's starter images, or any Linux image of your own, public or private.

## Starter images

| Catalog id | Image | CUDA | Driver | PyTorch | Download |
| --- | --- | --- | --- | --- | ---: |
| `pytorch` | PyTorch 2.14 (default) | `13.0` | `580+` | `2.14.1` | `3.38 GB` |
| `pytorch-jupyter` | PyTorch 2.14 + JupyterLab | `13.0` | `580+` | `2.14.1` | `3.42 GB` |
| `cuda` | CUDA 13.0 | `13.0.3` | `580+` | None | `1.73 GB` |
| `pytorch-cu128` | PyTorch 2.11 (CUDA 12.8) | `12.8` | `570+` | `2.11.0` | `6.2 GB` |
| `cuda-12` | CUDA 12.8 | `12.8.2` | `570+` | None | `2.16 GB` |

On the rent form's **Software** step, choose **Starter image**, **Model** or **Your own image** under **What to run**. Every starter image is a tile that says what's inside it, and the one you choose is described in full beside the tiles. One the host can't run is shown greyed out, with the reason, for example a driver that's too old for its CUDA version. The newest image the host can run is chosen for you.

On starter images:

- `/workspace` is the folder a [backup](https://legion.ambient.xyz/docs/renting/stopping-and-backups#backups) copies. Keep your work there. After a rental stops, its files stay on the host for at least 24 hours and at most 72 hours, then are deleted. An interruptible rental set to delete on preemption loses them when preempted. See [Stopping, backups and how long your data is kept](https://legion.ambient.xyz/docs/renting/stopping-and-backups).
- Common tools are installed, such as git, rsync, tmux and jq.
- `pip install` goes into the system Python.

## Your own image

Choose **Your own image** and enter the image reference. The image can be on one of these registries:

- `docker.io`
- `ghcr.io`
- `nvcr.io`
- `quay.io`

Write the whole reference, such as `ghcr.io/acme/train:1`. A name with no owner, like `cuda`, is looked up on Docker Hub as `library/cuda`.

Legion checks the image before it rents. If the image can't be used, the rent form says why. Through the API, call [inspectImage](https://legion.ambient.xyz/docs/api/images/inspect-image) first.

A public image needs nothing more. For a private one, save a registry credential first: see [Private images](#private-images).

## Private images

Legion can run a private image from any registry that hands out pull tokens. That covers Docker Hub, GitHub's `ghcr.io`, GitLab, Quay, NVIDIA NGC, Harbor, Artifactory, Artifact Registry, Azure Container Registry and self-hosted registries with a token service. Your organization saves a **registry credential**: a username and a read-only token. Legion runs no registry for it and keeps no copy: the host pulls the image straight from your registry.

When the image you enter is private, the **Registry credential** section of the rent form says so. If one of your saved credentials fits the image, the section says **Uses: acme on ghcr.io** and you can press **Change** to pick another one for this rental. If none fits, press **Add a credential**:

1. The form starts with the image you entered (**Image to check**). Legion reads the registry and the **Path prefix** from it, and the prefix can be edited. Leave it empty to use the credential for every image on the registry.
2. Enter a **Username** and a **Token**. A **Name** is optional.
3. Press **Save credential**. Legion checks that the credential can read the image before it saves anything.
4. Press **Rent**.

You can also add one under **Settings**, then **Registry credentials**, which lists them all.

To give a container tokens or other values at run time, use [secret environment variables](https://legion.ambient.xyz/docs/renting/configuration#secrets) rather than building them into the image.

Use a read-only token made only for Legion, so you can revoke it without touching anything else. What to enter depends on the registry:

| Registry | Username | Token |
| --- | --- | --- |
| `docker.io` | Your Docker ID, not your email address | A personal access token with **Read-only** permission |
| `ghcr.io` | Your GitHub username | A classic personal access token with only the `read:packages` scope. Fine-grained tokens don't work with `ghcr.io` |
| `nvcr.io` | `$oauthtoken`, exactly as written (the form fills it in) | An NGC API key |
| `quay.io` | A robot account's name, like `acme+legion` | The robot account's token, with **Read** access to the repository |
| GitLab (`registry.gitlab.com`) | The username shown when you create a deploy token | A deploy token with only the `read_registry` scope |
| Artifact Registry (`*-docker.pkg.dev`) | `_json_key_base64` | A service account key with the Artifact Registry Reader role, base64 encoded on one line |
| Azure (`*.azurecr.io`) | The token name, or the application ID of a service principal | A repository-scoped token, or a service principal secret with the `AcrPull` role. Don't use the admin user |
| Harbor and others | A robot account's name, like `robot$project+legion` | The robot account's secret, with pull permission only |

For any other registry, enter the username and token its administrator gave you.

### Several credentials, matched automatically

An organization can save up to 20 credentials, and several for one registry host. Each has a **path prefix**: the part of the image path it covers. A credential for `ghcr.io` with the prefix `acme` is used for `ghcr.io/acme/model`, and another for `ghcr.io` with the prefix `other-org` is used for that organization's images. An empty prefix covers every image on the host.

When you rent, Legion uses the credential whose host matches the image and whose prefix is the longest match. The rent form shows it as **Uses: acme on ghcr.io**, with the name you gave it, or the host and prefix when it has none. **Change** picks a different credential on the same host for this rental. A rental keeps the credential it started with.

Saving never replaces another credential. A second credential with the same host and prefix is refused, and the answer names the one that exists: replace its token instead.

### Who can do what

Any member can rent with a saved credential. Adding one, replacing its token, renaming it and removing it need the `registry.manage` permission, which owners have. Everyone in the organization can see the list (name, host, prefix, username, who saved it, when it was last used), never a token.

Removing a credential is refused while a rental that may still pull with it exists. The answer names those rentals: stop or delete them, then remove it. Rentals already running keep running, and a rental that has to pull its image again needs its credential until it ends.

If the registry later refuses the credential, for example because the token was revoked, the rent form says so and offers to save a new token. A rental whose pull is refused fails with the reason. An organization can save 20 times an hour, including saves that fail.

### What happens to the token

- Legion keeps it encrypted and never shows it again, to anyone.
- It's never sent to a host. When a host pulls your image, Legion exchanges the credential at the registry's own token service for a pull token for that one repository. The registry issues it and decides how long it lasts, and it is short-lived. It can read every tag in that repository, not only the image you rented.
- The registry's token service is found when you save and pinned: the token is only ever sent there.
- The image runs on the provider's machine, where the provider has full access. Treat what's in the image as visible to that provider, and don't build secrets into it.

### Not supported yet

- **AWS ECR** (`*.dkr.ecr.*.amazonaws.com`). An ECR password is a 12-hour token made from AWS keys. A host could only pull with a long-lived secret, which Legion never sends to a host. Push the image to a registry in the table above, or mirror it to one. Images on `public.ecr.aws` are public and need no credential.
- **Registries that only accept a username and password** and have no token service, for the same reason.
- Registries on an IP address, a port other than 443, or a name with a single label, and any address inside Legion's own network.

Through the API: [createRegistryCredential](https://legion.ambient.xyz/docs/api/images/create-registry-credential), [listRegistryCredentials](https://legion.ambient.xyz/docs/api/images/list-registry-credentials), [updateRegistryCredential](https://legion.ambient.xyz/docs/api/images/update-registry-credential), [deleteRegistryCredential](https://legion.ambient.xyz/docs/api/images/delete-registry-credential) and [detectRegistryCredential](https://legion.ambient.xyz/docs/api/images/detect-registry-credential), which splits an image reference into host and prefix without saving anything. [createRental](https://legion.ambient.xyz/docs/api/rentals/create-rental) takes an optional `registry_credential_id` to use a credential other than the matched one. The older [putRegistrySignIn](https://legion.ambient.xyz/docs/api/images/put-registry-sign-in) operations still work for a credential that covers a whole host and are deprecated. From a terminal, see [legion registry](https://legion.ambient.xyz/docs/cli/commands#registry-credentials).

## What Legion adds

Any Linux image works. Legion adds its own SSH server and init process to your container, so SSH and the web terminal work whatever image you choose. Your image's `ENTRYPOINT`, `CMD`, `USER` and environment are kept.

If your image starts its own init system, such as systemd or s6, it runs beneath Legion's init.

## When your process exits

If your image's own process exits, the rental stays up and SSH keeps working. The login message shows its exit status. Its last output is in `/.legion/run/workload.log`.

## Shared memory

`/dev/shm` is half the rental's memory, between 1 GiB and 64 GiB.
