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

# Template Build

> Build a reusable template and create a machine from it.

<Warning>
  Template builds require the microVM runtime and template build support in the
  target deployment.
</Warning>

## Setup

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
uv pip install "${NULLSPACE_SDK_INSTALL_SPEC:-nullspace-sdk==1.0.0}"
export NULLSPACE_API_KEY=ns_live_...
export NULLSPACE_API_URL=https://api.your-nullspace-domain
```

## Python

```python theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
from nullspace import Machine, Template, default_build_logger

builder = (
    Template()
    .from_ubuntu_image("22.04")
    .apt_install(["curl"])
    .run_cmd("curl --version > /tmp/curl-version.txt")
    .set_runtime_envs({"APP_ENV": "demo"})
)

build = Template.build(
    builder,
    name="demo-curl",
    tags=["stable"],
    on_log_entry=default_build_logger(),
)
print(f"template built: {build.name}")

with Machine.create(template=build.canonical_ref, timeout=120) as machine:
    print(machine.commands.run("cat /tmp/curl-version.txt", shell=True).stdout.splitlines()[0])
    print(machine.commands.run("printenv APP_ENV", shell=True).stdout.strip())

Template.delete(build.canonical_ref)
```

## Production note

Use tags such as `:dev`, `:stable`, and `:prod` to promote builds without
changing application code.

Guide: [Templates](../templates/overview).
