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

# Build Template

`novita template create` builds a Dockerfile directly into a reusable sandbox template. It reads the Dockerfile, builds the image, applies sandbox settings (start / ready command, CPU, memory), and registers the result under the template name — which you can then pass to `sandbox.create(...)`.

***

## Usage

```bash CLI icon="terminal" theme={"system"}
novita template create <template-name> [options]
```

## Argument

| Argument          | Required | Description                                                                                                                        |
| ----------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `<template-name>` | Yes      | Template name to create or rebuild. Must be lowercase and contain only letters, numbers, dashes and underscores (`^[a-z0-9-_]+$`). |

## Options

| Option                        | Default                                | Description                                                                                                                                             |
| ----------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-p, --path <path>`           | current directory                      | Change the root directory where the command is executed. Dockerfile lookup and the build file context are resolved relative to it.                      |
| `-d, --dockerfile <file>`     | `novita.Dockerfile`, then `Dockerfile` | Path to the Dockerfile, relative to the root directory. Without this option the CLI looks for `novita.Dockerfile` first and falls back to `Dockerfile`. |
| `-c, --cmd <start-command>`   | —                                      | Command executed when the sandbox is started. Must be used together with `--ready-cmd`.                                                                 |
| `--ready-cmd <ready-command>` | —                                      | Command that must exit 0 for the template to be considered ready. Can be used on its own.                                                               |
| `--cpu-count <cpu-count>`     | `2`                                    | Number of CPUs used to run the sandbox.                                                                                                                 |
| `--memory-mb <memory-mb>`     | `2048`                                 | Memory in megabytes used to run the sandbox. Must be an even number.                                                                                    |
| `--no-cache`                  | off                                    | Skip the build cache when building the template.                                                                                                        |
| `--patch-cmd <cmd>`           | —                                      | Command to patch an incompatible base image at the end of the provision phase.                                                                          |

## Behavior and validation

* Authentication is required: log in with `novita auth login` or set `NOVITA_API_KEY` in the environment.
* Providing `--cmd` without `--ready-cmd` fails with `Both start and ready commands must be provided.`; `--ready-cmd` alone is allowed.
* An invalid template name or an odd `--memory-mb` value aborts the build before anything is sent to the server.
* Build logs are streamed to the terminal. On success the CLI prints Python / JS snippets showing how to create a sandbox from the new template.

## Examples

An example Dockerfile used by the commands below:

```docker Dockerfile icon="docker" theme={"system"}
FROM python:3.12

WORKDIR /home/user/app

RUN pip install --no-cache-dir flask requests

COPY app.py .

ENV PORT=8080

CMD ["python", "app.py"]
```

### Minimal build

Reads `./novita.Dockerfile` (or `./Dockerfile`) in the current directory:

```bash CLI icon="terminal" theme={"system"}
novita template create my-python-template
```

### Specify a Dockerfile explicitly

Point the build at a specific Dockerfile relative to the root directory:

```bash CLI icon="terminal" theme={"system"}
novita template create my-python-template --dockerfile ./Dockerfile
```

### Full build

Custom root directory, resources, start/ready commands, and no cache:

```bash CLI icon="terminal" theme={"system"}
novita template create my-python-template \
  --path ./app \
  --dockerfile ./docker/novita.Dockerfile \
  --cpu-count 4 \
  --memory-mb 2048 \
  --cmd "python app.py" \
  --ready-cmd "curl -sf http://localhost:8080/health" \
  --no-cache
```

Once the build finishes, create sandboxes from the template by name:

```typescript JavaScript & TypeScript icon="js" theme={"system"}
const sandbox = await novita.sandbox.create('my-python-template')
```
