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

# Template

> Complete reference for HopX CLI template commands - list, info, build, and delete templates. Manage pre-built and custom templates for sandbox creation.

Manage templates for HopX sandboxes using the `template` command (alias: `tpl`). List available templates, view template details, build custom templates, and delete templates.

## Command Syntax

```bash theme={null}
hopx template <subcommand> [options]
```

## Subcommands

### `list`

List all available templates.

**Syntax:**

```bash theme={null}
hopx template list [OPTIONS]
```

**Options:**

* `--output, -o FORMAT` - Output format: `table`, `json`, `plain` (default: `table`)

**Examples:**

```bash theme={null}
# List all templates
hopx template list

# List with JSON output
hopx template list --output json
```

**Expected Output (Table):**

```
┌──────────────┬──────────────────────┬─────────────┐
│ Name         │ Description          │ Category    │
├──────────────┼──────────────────────┼─────────────┤
│ python       │ Python 3.11          │ language    │
│ nodejs       │ Node.js 20           │ language    │
│ code-interpreter │ Data science stack │ development │
└──────────────┴──────────────────────┴─────────────┘
```

**Exit Codes:**

* `0` - Success
* `3` - Authentication error

### `info`

Get detailed information about a template.

**Syntax:**

```bash theme={null}
hopx template info TEMPLATE_NAME [OPTIONS]
```

**Arguments:**

* `TEMPLATE_NAME` - Template name or ID (required)

**Options:**

* `--output, -o FORMAT` - Output format: `table`, `json`, `plain` (default: `table`)

**Examples:**

```bash theme={null}
# Get template info
hopx template info python

# Get info with JSON output
hopx template info code-interpreter --output json
```

**Expected Output (Table):**

```
┌─────────────┬─────────────────────────────────────┐
│ Property    │ Value                               │
├─────────────┼─────────────────────────────────────┤
│ Name        │ python                              │
│ ID          │ 123                                 │
│ Description │ Python 3.11 with pip                │
│ Category    │ language                            │
│ Language    │ python                              │
└─────────────┴─────────────────────────────────────┘
```

**Exit Codes:**

* `0` - Success
* `3` - Authentication error
* `4` - Template not found

### `build`

Build a custom template from a Dockerfile.

**Syntax:**

```bash theme={null}
hopx template build [OPTIONS]
```

**Options:**

* `--name TEXT` - Template name (required)
* `--dockerfile PATH` - Path to Dockerfile
* `--image TEXT` - Base image (e.g., `python:3.11`, `node:20`)
* `--context PATH` - Build context directory
* `--output, -o FORMAT` - Output format: `table`, `json`, `plain` (default: `table`)

**Examples:**

```bash theme={null}
# Build template from Dockerfile
hopx template build --name my-app --dockerfile ./Dockerfile

# Build with context directory
hopx template build --name my-app --dockerfile ./Dockerfile --context ./build-context
```

**Expected Output:**

```
Building template: my-app
✓ Template built successfully
✓ Template ID: tpl_abc123
```

**Exit Codes:**

* `0` - Success
* `1` - Build failed
* `3` - Authentication error

### `delete`

Delete a custom template.

**Syntax:**

```bash theme={null}
hopx template delete TEMPLATE_ID [OPTIONS]
```

**Arguments:**

* `TEMPLATE_ID` - Template ID to delete (required)

**Options:**

* `--force` - Skip confirmation prompt

**Examples:**

```bash theme={null}
# Delete template
hopx template delete tpl_abc123

# Delete without confirmation
hopx template delete tpl_abc123 --force
```

**Expected Output:**

```
✓ Template deleted: tpl_abc123
```

**Exit Codes:**

* `0` - Success
* `3` - Authentication error
* `4` - Template not found

## Shell Scripting Examples

### List and Filter Templates

```bash theme={null}
#!/bin/bash

# List templates and filter by category
hopx template list --output json | jq '.[] | select(.category == "language")'
```

### Build and Use Custom Template

```bash theme={null}
#!/bin/bash
set -e

# Build custom template
TEMPLATE_ID=$(hopx template build --name my-app --dockerfile ./Dockerfile --output json | jq -r '.id')

# Create sandbox from custom template
SANDBOX_ID=$(hopx sandbox create --template-id "$TEMPLATE_ID" --output json | jq -r '.id')

echo "Created sandbox $SANDBOX_ID from template $TEMPLATE_ID"
```

## Related

* **[CLI Quickstart](/cli/quickstart)** - Get started with CLI
* **[Sandbox Commands](/cli/commands/sandbox)** - Create sandboxes from templates
* **[Python SDK: Template Builder](/sdk/python/template-builder)** - Python SDK template building
* **[JavaScript SDK: Template Builder](/sdk/javascript/template-builder)** - JavaScript SDK template building
* **[API: Templates](/api/control-plane/list-templates)** - REST API endpoints

## Next Steps

* Learn about [Sandbox Management](/cli/commands/sandbox) to create sandboxes from templates
* Explore [Template Building](/sdk/python/template-builder) for advanced template creation
* Review [Pre-built Templates](/supported-languages) for available templates
