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

# Container Templates

> Create custom Docker environments

## Overview

Build custom agent environments from any Docker image.

<Note>
  **Container templates** = Custom Docker environments
  **Saved templates** (`instance.snapshot()`) = Workspace snapshots
</Note>

## Create a Template

```typescript theme={null}
const client = new In10ntClient();

const template = await client.templates.create({
  name: 'python-ml',
  image: 'python:3.11-slim',
  registryType: 'dockerhub',
  registryAuth: {  // Optional: for private registries
    username: 'user',
    password: 'pass'
  }
});

await template.waitUntilReady();  // Wait for build
```

### Parameters

| Parameter      | Type     | Required | Description                                     |
| -------------- | -------- | -------- | ----------------------------------------------- |
| `name`         | `string` | Yes      | Human-readable template name                    |
| `image`        | `string` | Yes      | Base Docker image (e.g., `python:3.11-slim`)    |
| `registryType` | `string` | Yes      | Registry type: `dockerhub`, `private`, or `gcr` |
| `description`  | `string` | No       | Template description                            |
| `registryAuth` | `object` | No       | Authentication for private registries           |

### Registry Types

* `dockerhub` - Public Docker Hub
* `private` - Private registries
* `gcr` - Google Container Registry

### Build Status

* `building` → `ready` or `failed`

## Wait for Build

```typescript theme={null}
await template.waitUntilReady({
  timeout: 300000,     // 5 min (default)
  pollInterval: 5000   // Check every 5s
});
```

## List & Get Templates

```typescript theme={null}
// List all
const templates = await client.templates.list();

// Get specific template
const template = await client.templates.get('tmpl_123');
console.log(template.status);  // building | ready | failed

// Delete template
await template.delete();
```

## Use Template

```typescript theme={null}
// Build template
const template = await client.templates.create({
  name: 'ml-env',
  image: 'python:3.11-slim',
  registryType: 'dockerhub'
});

await template.waitUntilReady();

// Use it
const instance = await client.instances.create({
  name: 'ml-agent',
  description: 'ML tasks',
  containerTemplateId: template.templateId
});

await instance.run('Train classifier');
```

## Private Registry

```typescript theme={null}
const template = await client.templates.create({
  name: 'private-env',
  image: 'registry.example.com/myimage:latest',
  registryType: 'private',
  registryAuth: {
    username: process.env.REGISTRY_USER,
    password: process.env.REGISTRY_PASS
  }
});
```

<Warning>
  Use environment variables for credentials
</Warning>

## Quick Examples

```typescript theme={null}
// Python
await client.templates.create({
  name: 'python',
  image: 'python:3.11-slim',
  registryType: 'dockerhub'
});

// Node.js
await client.templates.create({
  name: 'node',
  image: 'node:20-alpine',
  registryType: 'dockerhub'
});

// CUDA/GPU
await client.templates.create({
  name: 'cuda',
  image: 'nvidia/cuda:12.2-runtime',
  registryType: 'dockerhub'
});
```

## Saved Templates (Snapshots)

Saved templates are workspace snapshots created with `instance.snapshot()`. They are managed via `client.savedTemplates`:

```typescript theme={null}
// List saved templates
const saved = await client.savedTemplates.list();

// Delete a saved template
await client.savedTemplates.delete('old-template');

// Clone from a saved template
const clone = await client.instances.createFromSavedTemplate({
  templateName: 'web-app-template',
  newInstanceName: 'my-web-app-v2'
});
```

## Template vs Saved Template

| Feature    | Container Template              | Saved Template              |
| ---------- | ------------------------------- | --------------------------- |
| Method     | `client.templates.create()`     | `instance.snapshot()`       |
| Creates    | Custom Docker environment       | Workspace snapshot          |
| Build time | 2-5 minutes                     | Instant                     |
| Use case   | Base environments               | Reuse workspaces            |
| Clone with | `containerTemplateId` in create | `createFromSavedTemplate()` |

## HTTP API Reference

### Create Template

```bash theme={null}
curl -X POST https://in10t-api-v2.fly.dev/container-templates \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "python-ml",
    "image": "python:3.11-slim",
    "registryType": "dockerhub"
  }'
```

### List Templates

```bash theme={null}
curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://in10t-api-v2.fly.dev/container-templates
```

### Get Template Status

```bash theme={null}
curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://in10t-api-v2.fly.dev/container-templates/{templateId}/status
```

### Delete Template

```bash theme={null}
curl -X DELETE https://in10t-api-v2.fly.dev/container-templates/{templateId} \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### List Saved Templates

```bash theme={null}
curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://in10t-api-v2.fly.dev/saved-templates
```
