# Images

Build a beam image with Pi, layer on configuration, and select a model at startup.



**Install the client tools and sign in**

Beams is a [Teleport](https://goteleport.com) project and uses [official Teleport client tools](https://goteleport.com/download/client-tools/).

The client tools include `tsh` to sign in and run commands, and `tctl` to administer your cluster if you have permission.



Cluster: `example.beams.run`. Edit this example to use your cluster name.

Install version **18.11.10** of the client:

**macOS**

Download and open the macOS installer, then follow its instructions.

```sh
curl -O https://cdn.teleport.dev/teleport-tools-18.11.10.pkg
open teleport-tools-18.11.10.pkg
```

**Linux**

For Linux x86-64, download and install the client tools:

```sh
curl -O https://cdn.teleport.dev/teleport-v18.11.10-linux-amd64-bin.tar.gz
tar -xzf teleport-v18.11.10-linux-amd64-bin.tar.gz
sudo ./teleport/install
```

**Windows**

For Windows x86-64, run these commands in PowerShell. Add the extraction directory (`$env:LOCALAPPDATA\Teleport`) to your user PATH to use `tsh` in future terminals; the last command adds it to this terminal's PATH.

```powershell
Invoke-WebRequest -Uri https://cdn.teleport.dev/teleport-v18.11.10-windows-amd64-bin.zip -OutFile teleport.zip
Expand-Archive -Path teleport.zip -DestinationPath "$env:LOCALAPPDATA\Teleport" -Force
$env:Path += ";$env:LOCALAPPDATA\Teleport"
```

Follow the official client [tools install guide](https://goteleport.com/download/client-tools/) for other versions and architectures.

Check that you’re running v18.11.10 of the client with `tsh version`.

```sh
tsh version
```

**Passwordless**

I sign in without a password (e.g. a passkey).

```sh
tsh login --proxy='example.beams.run' --auth=passwordless
```

**Password \& MFA**

I have a password & MFA set up for my account:

Replace `you@example.com` with your Teleport username.

```sh
tsh login --proxy='example.beams.run' --user=you@example.com
```

**SSO**

I sign in with SSO (e.g. Okta, GitHub, SAML).

```sh
tsh login --proxy='example.beams.run'
```

## Build an image with just Pi

Start a fresh beam and run `pi --version`. Pi is already installed; there’s nothing to install in the running beam. To get that result, save this as `phase.yaml`. The `default:v1` base image already includes Node.js and npm, so the build command only installs Pi.

**phase.yaml**

```yaml
version: v1
metadata:
  name: pi-tools
  from: default:v1
commands:
  - shell: npm install --global --prefix /usr/local @earendil-works/pi-coding-agent@1.5.2
```

From the directory containing `phase.yaml`, build the image, then start a beam from it:

**Local terminal**

```sh
tsh phase apply -f phase.yaml
tsh beams add --phase=pi-tools
```

Run `pi --version` in the new beam. It should print `1.5.2`.

The `commands` list makes `pi-tools` a **rebuild phase**. Teleport Beams runs those commands during image assembly, saves the resulting files outside `/home`, and reruns the commands every **24 hours** or after a successful refresh of a non-static parent. New beams use the latest successful image. The rebuild doesn’t change a beam that’s already running, and the pinned install won’t pick up a new Pi version until you change the pin.

<!-- illustration
id: pi-rebuild-phase
style: docs-isometric
type: static
title: Pi is installed at build time
description: The same install command runs again on refresh, not when a beam starts.

Show default:v1 as an image plate pointing to a thick pi-tools rebuild block. Put npm install under pi-tools as the command replayed on refresh. The arrow means parent → child, not an instruction to reinstall Pi when a Beam starts.
-->

## Copy in your Pi defaults

The next beam should start with your Pi preferences, too. Save this minimal config next to `phase.yaml`:

**settings.json**

```json
{
  "defaultThinkingLevel": "off"
}
```

Append a second document to `phase.yaml`, including the `---` separator:

**Append to phase.yaml**

```yaml
---
version: v1
metadata:
  name: pi-config
  from: pi-tools
files:
  - from: ./settings.json
    to: /opt/pi-config/settings.json
```

Apply the file and start a beam from `pi-config` this time:

**Local terminal**

```sh
tsh phase apply -f phase.yaml
tsh beams add --phase=pi-config
```

**Note**

Newly created phases and build status changes may take a short time to appear in listings. `phase apply` will wait for an earlier operation to finish before starting a replacement of the phase.

Now `/opt/pi-config/settings.json` is in the image. This is the **copy phase**: `files` is like Dockerfile `COPY`. It adds files without running an install command. When `pi-tools` rebuilds, Teleport Beams reapplies the saved copy layer on top of it. The file is outside `/home`, so it’s available in the image but isn’t yet in Pi’s per-user config directory.

<!-- illustration
id: pi-copy-phase
style: docs-isometric
type: static
title: The copy phase sits on top of the rebuild phase
description: New beams from pi-config get both the Pi install and the copied defaults.

Extend the same default:v1 → pi-tools path with an arrow to a thin pi-config copy plate. Label the copied file settings.json. Show that pi-config is a child of pi-tools, not a second install or a separate base image.
-->

## Connect Pi to the beam’s inference endpoint

You want to open Pi and have it ready to use the beam’s inference endpoint. The config file can be baked into the image, but the endpoint URL comes from the running beam’s `OPENAI_BASE_URL`. Write the URL into Pi’s config at startup and leave the key as a reference to `OPENAI_API_KEY`, so the credential never goes into the image or the generated config.

Save this script as `init-pi.js` next to `phase.yaml`:

**init-pi.js**

```js
const fs = require('node:fs');
const path = require('node:path');

function requiredEnv(name) {
  const value = process.env[name];
  if (!value) throw new Error(`${name} is not set`);
  return value;
}

const baseUrl = requiredEnv('OPENAI_BASE_URL');
requiredEnv('OPENAI_API_KEY');
process.umask(0o077);

const dir = path.join(process.env.HOME, '.pi', 'agent');
const read = file => fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
const write = (file, value) => fs.writeFileSync(file, JSON.stringify(value, null, 2) + '\n');

fs.mkdirSync(dir, { recursive: true });
const provider = 'teleport-openai';
const model = 'gpt-6.1-sol';
const modelsFile = path.join(dir, 'models.json');
const models = read(modelsFile);
models.providers ??= {};
models.providers[provider] = {
  baseUrl,
  api: 'openai-responses',
  apiKey: '$OPENAI_API_KEY',
  models: [{ id: model, name: model }],
};
write(modelsFile, models);

const settingsFile = path.join(dir, 'settings.json');
write(settingsFile, {
  ...read('/opt/pi-config/settings.json'),
  ...read(settingsFile),
  defaultProvider: provider,
  defaultModel: model,
});
```

Replace the `files` list in the `pi-config` document with the one below and add `services` at the same level. Leave `pi-tools` and `pi-config`’s `metadata` unchanged.

**pi-config in phase.yaml**

```yaml
files:
  - from: ./settings.json
    to: /opt/pi-config/settings.json
  - from: ./init-pi.js
    to: /opt/pi-config/init-pi.js
services:
  - name: init-pi
    type: pre-start
    context: user
    command: node
    args:
      - /opt/pi-config/init-pi.js
```

The **startup service** runs as the beam user when a beam starts, not during the copy build. It writes to `~/.pi/agent`, preserving unrelated settings and providers, and selects the configured Teleport model. If inference isn’t configured on your cluster, the service logs the missing variable; check `beamctl logs init-pi` from inside the beam.

## Make the model a variable

Switching models shouldn’t require editing the startup script. In `init-pi.js`, replace the hard-coded `const model` line with:

**init-pi.js**

```js
const model = requiredEnv('PI_MODEL_ID');
```

Then add `env` to the `init-pi` service, alongside `args`. The value below is editable in this guide; changing it updates the example, not your phase.



**init-pi service in phase.yaml**

```yaml
    env:
      - name: PI_MODEL_ID
        value: "gpt-6.1-sol"
```

`PI_MODEL_ID` is now an environment variable passed to the startup service. The script uses it both to register the model and to select it as Pi’s default.

## Apply a model change

To move from `gpt-6.1-sol` to `gpt-6.2-sol`, change `PI_MODEL_ID` in `phase.yaml` to `gpt-6.2-sol`, assuming that model is available through your cluster’s inference endpoint. Apply the file again, then start a **new** beam from the same `pi-config` phase:

**Local terminal**

```sh
tsh phase apply -f phase.yaml
tsh beams add --phase=pi-config
```

Reapplying the file runs its stages in order under the same phase names. The new beam runs `init-pi` with the new model ID; an already-running beam keeps its existing config. In the new beam, run `pi --list-models` to verify that `teleport-openai` lists `gpt-6.2-sol`, then run `pi`.

## Diagnose a failed build

If a build fails, the phase keeps its last successful image. Fix its `phase.yaml` and reapply it. Disconnecting from `tsh` does not stop a running command build. Check `tsh phase ls` before retrying after a disconnection.

When a failed snapshot is available, the error includes a command to open a beam for inspection. Run that command and read `/var/log/beam/build.log` inside the beam. Use `tsh phase ls-failed` to find recent failed snapshots. They are temporary and may expire, so do not use them as your only copy of important work. See [inspect a specific snapshot](#inspect-a-specific-snapshot) for the explicit reference format.

## Services in a phase configuration

Services start programs whenever a beam starts from your phase. Use them to prepare the user's environment or run a long-lived process. Each service requires a `name`. Reusing an inherited service's name replaces its definition rather than starting a second instance.

Use `type: pre-start` for setup that must finish before background services start. Use `type: background` (the default) for a long-lived process. `context` selects which kinds of beams run the service:

| Context          | When the service runs                                                                      |
| ---------------- | ------------------------------------------------------------------------------------------ |
| `user` (default) | Interactive snapshot builds and beams started with `tsh beams add`.                        |
| `rebuild`        | Command-based builds only.                                                                 |
| `snapshot`       | Interactive snapshot builds only.                                                          |
| `runtime`        | Beams started with `tsh beams add` only.                                                   |
| `build`          | Command-based and interactive snapshot builds.                                             |
| `all`            | Command-based builds, interactive snapshot builds, and beams started with `tsh beams add`. |

Copy builds never run services, including inherited services. This prevents startup programs from changing files during the copy. Service definitions are still saved for beams started from the resulting image.

Pre-start services run in declaration order before background services start. A failure is logged and the remaining services still run. SSH remains available for diagnosis. In a command build, any pre-start failure fails the build before its commands run. Inside the beam, use `beamctl logs <service-name>` to read a service's output, or `beamctl logs --follow <service-name>` to follow it. Both pre-start and background services have their own logs.

Services run as `beams`. Use explicit `sudo` when a service needs root privileges. Replacing a service also replaces its type and context.

## Inspect a specific snapshot

For a failed build, prefer the inspection command printed in the error. To select a particular saved or failed image yourself, supply its explicit reference:

```sh
tsh beams add --phase='app-work@sha256:<digest>'
```

You must have access to the phase that produced the snapshot, and its recorded identity must still be valid. Failed snapshots must not have expired. Inspect `/var/log/beam/build.log` inside the resulting beam. The inspection beam cannot save changes back. To save a repair, update the phase's configuration or open an eligible snapshot phase with `tsh phase edit`.

## Reuse an explicit snapshot reference

These commands are for snapshots already captured in a build beam. For everyday work, use `tsh phase snapshot` and `tsh phase add NAME --fork` inside the beam instead.

```sh
tsh phase snapshot app-work --from='parent@sha256:<digest>'
tsh phase add app-experiment --fork-from='parent@sha256:<digest>'
```

The prefix names the snapshot's parent, not its originating phase. Saving requires a snapshot created for the existing target. It cannot save another phase's snapshot to that target, replace build commands, or change the parent. It saves only the referenced contents, not later changes in the running beam. `--final` cannot be combined with `--from`.

Forking creates a new phase from the captured filesystem. Outside a beam, a reference whose parent is a built-in base image also requires `--region` to identify the snapshot's original region. Copy and rebuild phases cannot be forked, including through explicit digests. Snapshot references never move images between regions.

## Understand the local beam helpers

The following helpers are available inside build beams for troubleshooting. They communicate with the local builder, not directly with Teleport. You do not need them for normal snapshot, fork, or YAML workflows.

| Helper          | Behavior                                                                                                                                                                         |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `beam-snapshot` | Captures and uploads a snapshot, then prints a reference. It does not save the snapshot to the phase. Unless accepted and retained by Teleport, the uploaded image is temporary. |
| `beam-finalize` | Captures a final snapshot and ends the build. Teleport observes and validates the result before saving it to the phase.                                                          |
| `beam-abandon`  | Ends the build without capturing another snapshot. Previously saved phase snapshots remain available.                                                                            |

An older or explicitly captured image may be listed as `static`. It does not receive parent updates, including security fixes, and cannot be a parent of a new phase. To restore updates, edit it and save an allowed snapshot with `tsh phase snapshot --force --final`.

## Start builds without opening a console

Use `--no-console` with `tsh phase add` or `tsh phase edit` to provision a build beam without connecting to its shell. The command prints the identifier you need to reconnect. For automation, add `--format=json` or `--format=yaml`:

```sh
tsh phase add automated-work --no-console --format=json
tsh beams ssh build-beam
```

Set build-beam to the `build_beam` identifier in the response, which also includes the phase name and build state. An interactive build still needs an explicit snapshot before it ends.

For builds started with `--commands-file`, `--no-console` returns after provisioning, without streaming logs or waiting for the commands to finish. A successful exit means the build started. Check `tsh phases ls` for its result. Without `--no-console`, command builds stream logs and wait for completion.

Copy builds still transfer files, save, and finalize before returning. Local `--fork` still captures the current filesystem before provisioning.

With `tsh phase apply -f phase.yaml --no-console`, command logs are suppressed, but stage summaries remain visible. The command waits for every stage to finish before starting its child. A failed stage stops the apply.

## Structured command output

Use `--format=json` or `--format=yaml` for automated builds and snapshots. Interactive `phase add` and `phase edit` require text output when opening a build console. Add `--no-console` to return structured output after provisioning, including the `build_beam` identifier for connecting later. With `phase apply`, progress and logs go to stderr while stdout contains the completed phases.


## Next steps

* For all supported fields and refresh behavior, see the [phase API reference](/docs/api/phase/#yaml-configuration-reference).
