# Snapshots

Interactive runtimes with snapshots.



Let's start with some terminology:

A beam runtime is an ephemeral micro-VM that expires in 11 hours. Each beam has an identity, state and a virtual network.
A phase is a versioned and layered images for beam runtimes. A phase holds filesystem state and its build instructions.

<!-- illustration
id: beam-phase
style: docs-isometric
type: static
title: A beam runtime and phases.
description: Beam runtimes and phases.

Show a beam runtime block that references phase - a versioned image with layers. The beam block has a foundation - a phase, this phase has a dashed
line to a layered phases.

-->

You can combine beams and phases to create reusable images, create forks and snapshots.
Let's start an interactive **build beam** micro-VM that supports snaphots in `/home` folder.

**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'
```

## Start a beam

**Local terminal**

```sh
tsh phase add workspace
```

This command created the build beam and an associated phase with the same name. You can snaphshot versions in `/home` folder of this beam, 
and phase `workspace` will add layer on each snapshot. Let's give it a try:

**Build beam: workspace**

```sh
mkdir -p ~/app
printf '<h1>Hello from my workspace</h1>\n' > ~/app/index.html
```

## Snapshot

**Build beam: workspace**

```sh
tsh phase snapshot
```

This saves filesystem changes since the last edit and updates the associated phase `workspace`.

**Warning**

Snapshots are only capturing changes in the `/home` folder!

Once you are done, you can finalise the changes to the `workspace` phase. 

**Build beam: workspace**

```sh
tsh phase snapshot --final
```

This command finalises the phase, shuts down and discards the build beam.

**Tip**

Snapshots preserve only files, not running processes, open terminals, or memory. Do not store credentials or sensitive data in your snapshots!

If you disconnect from the beam and did not run `tsh phase snapshot --final`, the changes will not be saved.
To reconnect back, use `tsh beams ssh workspace`.

## Return to saved work

To start a new build beam, run:

**Local terminal**

```sh
tsh phase edit workspace
```

A fresh build beam contains the last saved filesystem of `workspace`.

Edit your files and run `tsh phase snapshot --final` inside that beam to save again.


## When a snapshot is rejected

The default snapshot fails if you changed files outside the allowed paths. Inspect the rejected paths before deciding to omit them:

**Build beam: workspace**

```sh
tsh phase snapshot --force
```

`--force` leaves the running filesystem unchanged but excludes disallowed changes from the saved image. Those changes are lost when the beam is removed. See the [snapshot exclusions](https://goteleport.com/docs/beams/#files-excluded-from-snapshots).

For repeatable setup, copy stages, startup services, and `phase.yaml`, use the [phase API reference](/docs/api/phase/#yaml-configuration-reference).


## When an edit is unavailable

You cannot start a second edit while a phase has an active build. Reconnect to that build with `tsh beams ssh`, or finish it before starting another.

You also cannot edit or save changes to a snapshot phase while it has snapshot descendants. This includes indirect descendants and snapshot builds still in progress. Rebuild and copy children alone do not prevent editing.

If descendants prevent an edit, fork the saved snapshot into a new phase:

**Local terminal**

```sh
tsh phase add workspace-v2 --fork-from=workspace
```

The original and its dependents keep their existing contents and relationship.

You can read more on forks [here](/docs/phases/forks/).

## Saving, disconnecting, and ending a build

| Action                                                | Result                                                                                         |
| ----------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| `tsh phase snapshot` inside the build beam            | Saves allowed filesystem changes and keeps the beam running.                                   |
| `tsh phase snapshot --final` inside the build beam    | Saves successfully, then ends the build beam. Changes after capture are discarded.             |
| `exit` or Ctrl-D in the shell                         | Disconnects. It does not save files or end the beam.                                           |
| `tsh beams ssh <build-beam>` from your local terminal | Reconnects to the existing running workspace, including unsaved changes.                       |
| `tsh phase edit <phase>` after the build ends         | Creates a fresh build beam from the phase's last successful snapshot.                          |
| beam expiry or `tsh beams rm <build-beam>`            | Removes the beam and discards unsaved changes. The phase's last saved image remains available. |

Build beams expire after 11 hours. Check `tsh beams ls` for the expiry and identifier of a running beam. Save before that deadline. Expiry does not capture a final snapshot.
