> ## 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 for deployments

<Warning>
  This feature is in [public preview](/preview/roadmap).
</Warning>

An instance template defines the configuration for an [instance](/preview/instances): which
[image](/preview/images) to boot and an optional cloud-init script. Templates are used by
[deployments](/preview/deployments) to create instances with a consistent configuration.

Templates are immutable. To change a configuration, create a new template and update your
deployment to reference it.

## Create an instance template

```bash theme={null}
sf instance-templates create \
  --name prod-worker \
  --image ubuntu-22.04.5-cuda-12.7 \
  --cloud-init ./startup.sh
```

## Cloud-init

Pass a startup script or cloud-config YAML file via `--cloud-init`. The file is stored with the
template and applied to every instance created from it. Maximum size is 64 KB.

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

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

```bash theme={null}
sf instance-templates create --name ssh-ready \
  --image ubuntu-22.04.5-cuda-12.7 --cloud-init ./startup.sh
```

## List templates

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

```
NAME           IMAGE                      CLOUD-INIT  CREATED
prod-ubuntu    ubuntu-22.04.5-cuda-12.7   yes         Mar 23, 4:40pm
dev-debian     debian-12-cuda-12.7        -           Mar 26, 2:00pm
staging-base   ubuntu-22.04.5-cuda-12.7   yes         Mar 27, 2:00pm
```

## Get template details

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

```
│ ID          ntmpl_Gw5rT8mKn2Pj4Lx9Qf7Y
│ NAME        prod-ubuntu
│ IMAGE       ubuntu-22.04.5-cuda-12.7 (image_TQiHEBzCA18ToAQqBtOr_)
│ CLOUD-INIT  yes
└ CREATED     Mar 23, 4:40pm UTC
```

<Note>
  Template IDs are prefixed `ntmpl_` for backwards compatibility with the resource's previous name
  (`node-template`). The CLI, API, and SDK all refer to it as an instance template.
</Note>

## Delete a template

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

A template cannot be deleted while it is in use by a [deployment](/preview/deployments) or running
instance. Remove or update the referencing deployment first.

### API reference

See the [Instance Templates API](/preview/api-reference/instance-templates/list-instance-templates)
for programmatic access.
