> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sfcompute.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Instance templates

> Reusable instance configurations

> [!NOTE]
>
> This feature is in [public preview](https://docs.sfcompute.com/preview/roadmap.md#feature-states).

An instance template defines the configuration for an [instance](https://docs.sfcompute.com/preview/instances.md): which
[image](https://docs.sfcompute.com/preview/images.md) to boot and an optional [cloud-init](https://cloudinit.readthedocs.io/)
script. GPU clusters use templates to create instances with a consistent
configuration.

Templates are immutable. To change a configuration, create a new template and point the resource
that launches from it at the new template.

## Create an instance template

Create a template with a name and an image. Public images require the full
`sfc:image:sfcompute:public:...` name; SF Compute rejects the short trailing segment on its own.

```bash theme={null}
sf instance-templates create \
  --name prod-worker \
  --image sfc:image:sfcompute:public:ubuntu-24.04-cuda-13.2
```

A template captures one exact image build. SF Compute resolves the image name when you create the
template and stores that build's id, so later [versions](https://docs.sfcompute.com/preview/images.md#using-an-image) of the same
name never reach an existing template. Pass an image id to name the build explicitly; templates take
a name or an id, not the `name@<version>` pin form.

## Cloud-init

Pass a startup script or cloud-config YAML file via `--cloud-init`. The template stores the file and
applies it to every instance you create from it. Maximum size is 64 KB.

Cloud-init data isn't parameterized per instance: every instance created from the template receives
the same bytes. For example, this cloud-init script installs an SSH key.

```bash startup.sh theme={null}
#!/bin/bash

mkdir -p /root/.ssh
cat >>/root/.ssh/authorized_keys <<"EOF"
ssh-ed25519 AAAA... you@example.com
EOF
```

Create a template that uses the script.

```bash theme={null}
sf instance-templates create --name ssh-ready \
  --image sfc:image:sfcompute:public:ubuntu-24.04-cuda-13.2 --cloud-init ./startup.sh
```

## List templates

List the templates in your workspace.

```bash theme={null}
sf instance-templates list
```

```text theme={null}
----------------------------------------------------------------
NAME          IMAGE                   CLOUD-INIT  CREATED
prod-ubuntu   ubuntu-24.04-cuda-13.2  yes         Mar 23, 4:40pm
dev-debian    debian-12-cuda-12.7     -           Mar 26, 2:00pm
staging-base  ubuntu-24.04-cuda-13.2  yes         Mar 27, 2:00pm
```

## Get template details

Get a template by name or ID.

```bash theme={null}
sf instance-templates get prod-ubuntu
```

```text theme={null}
| ID             itmpl_Gw5rT8mKn2Pj4Lx9Qf7Y
| NAME           prod-ubuntu
| RESOURCE PATH  sfc:instance_template:acme:default:prod-ubuntu
| IMAGE          ubuntu-24.04-cuda-13.2 (image_Qb7dRk2mNp4Ls9Xf1Zt0)
| CLOUD-INIT     yes
| CREATED        Mar 23, 4:40pm PDT
```

> [!NOTE]
>
> Template IDs use the `itmpl_` prefix. You can still pass older IDs with the legacy `ntmpl_` prefix.

## Delete a template

Delete a template by name or ID.

```bash theme={null}
sf instance-templates delete prod-ubuntu
```

You can't delete a template while a GPU cluster uses it. Update or delete
the GPU cluster first.

## API reference

See the [Instance Templates API](https://docs.sfcompute.com/api-reference/instance-templates/list-instance-templates.md)
for programmatic access.
