# Make machines from a template

Make new machines that all start from one machine you set up once.

## Make a template

Requires [OSMates Pro](https://osmates.com/docs/editions#what-pro-adds).

1. Set the machine up the way new machines should start.
2. Shut it down.
3. Select it in the library and choose **Machine > Make Template**.

In Terminal, run `osmates template make base`.

The machine moves to **Templates** in the sidebar. A template never starts, and its settings, snapshots, and disk don't change. A suspended or temporary machine can't become one.

## Make a machine from a template

1. Select the template and choose **Machine > New Machine from Template**.
2. Enter a name and click **Create**.

To make a machine named `web` in Terminal:

```sh
osmates vm clone base web
```

The new machine is a [clone](https://osmates.com/docs/clone#clone-a-machine), and its writes never reach the template. Add `--snapshot` to start from one of the template's snapshots. The first start takes a little longer, about 20 seconds for a Windows disk.

Agents see your templates in `vm_list` and clone them with `vm_clone`, but can't make one. `osmates template list` shows each template and the machines made from it. To use one on another Mac, [push it to a registry](https://osmates.com/docs/registries).

## Change or delete a template

1. Select the template and choose **Machine > Turn Back into Machine**.
2. Start it, make your changes, and shut it down.
3. Choose **Machine > Make Template** again.

Machines made earlier keep their disks, and new machines use the changed template.

To delete a template, choose **Machine > Delete Machine**. Machines made from it keep working, and the space comes back once they're gone too.

## The template for agents

Commands that name no machine clone one template: Debian 13 without a desktop, with the guest agent. [Requirements](https://osmates.com/docs/requirements) lists its size. These commands clone it:

```sh
osmates run -- make test
osmates vm clone scratch --preset agent-sandbox
```

The first command that needs it makes the template, `agent-linux`, which adds a minute or two. Until then, an agent's `vm_run` and `vm_clone` without a source fail and say why. To make it ahead of time:

```sh
osmates vm create agent-linux --image agent-linux
```

To change it, turn it back into a machine and start it. Make your changes, then empty its machine ID so each clone makes its own:

```sh
osmates vm exec agent-linux -- truncate -s 0 /etc/machine-id
```

Then shut it down and make it a template again. While `agent-linux` is a machine, commands that need the template make another one. To start over, delete it, and the next command makes a new one.

For a macOS template with Xcode, see [Run Xcode tests in a macOS machine](https://osmates.com/docs/macos-xcode).
