> ## 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 Builder

> Fluent API for building custom sandbox templates in the HopX JavaScript/TypeScript SDK. Create custom templates from Docker images, configure resources, add build steps, and install dependencies using a fluent builder pattern. Complete reference for TemplateBuilder class with TypeScript examples and template configuration options.

**Version:** 0.1.22\
**Last Verified:** 2025-01-27\
**Package:** `@hopx-ai/sdk` on [npm](https://www.npmjs.com/package/@hopx-ai/sdk)

## Overview

The `Template` class provides a fluent API for building custom sandbox templates.

## Import

```typescript theme={null}
import { Template } from '@hopx-ai/sdk';
```

## Methods

### Base Image Methods

* `template.fromUbuntuImage(version: string): Template`
* `template.fromPythonImage(version: string): Template`
* `template.fromNodeImage(version: string): Template`
* `template.fromImage(image: string, auth?: AuthConfig): Template`

### Configuration Methods

* `template.copy(src: string, dest: string): Template`
* `template.run(command: string): Template`
* `template.env(key: string, value: string): Template`
* `template.expose(port: number): Template`
* `template.workdir(path: string): Template`
* `template.readyCheck(check: ReadyCheck): Template`
* `template.startCmd(command: string): Template`

### Building

```typescript theme={null}
async template.build(options?: BuildOptions): Promise<BuildResult>
```

**Example:**

```typescript theme={null}
const template = new Template()
    .fromPythonImage('3.11')
    .run('pip install flask')
    .expose(5000)
    .startCmd('python app.py');

const result = await template.build();
console.log(`Template ID: ${result.templateId}`);
```

***

## Related Classes

* **[Ready Checks](/sdk/javascript/ready-checks)** - Ready check utilities
* **[Sandbox](/sdk/javascript/sandbox)** - Use templates with `Sandbox.create({ template: ... })`

## See Also

* [Ready Checks](/sdk/javascript/ready-checks) - Learn about ready checks
* [Core Concepts: Templates](/core-concepts/templates) - Learn about templates

## Next Steps

Now that you understand template building, explore:

* [Ready Checks](/sdk/javascript/ready-checks) - Add readiness verification
* [Building Templates](/core-concepts/templates/building) - Learn template building concepts
* [Template Configuration](/core-concepts/templates/configuration) - Configure templates
* **[CLI Reference](/cli/introduction)** - Use HopX from the command line
* [Custom Templates](/cookbooks/advanced/custom-templates) - Build custom templates
