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

# Examples

These examples show the preferred `Novita` client entry point for template workflows.

## Build a Python image and run a sandbox

```python Python icon="python" theme={"system"}
from novita_sandbox import Novita

novita = Novita()

template = novita.template.new().from_python_image("3.12")
build = novita.template.build(template, "example-python-template")

sandbox = novita.sandbox.create(build.template_id)
result = sandbox.commands.run("python --version")
print(result.stdout)

sandbox.kill()
```

```js JavaScript & TypeScript icon="js" theme={"system"}
import { Novita } from 'novita-sandbox'

const novita = new Novita()

const template = novita.template.new().fromPythonImage('3.12')
const build = await novita.template.build(template, 'example-python-template')

const sandbox = await novita.sandbox.create(build.templateId)
const result = await sandbox.commands.run('python --version')
console.log(result.stdout)

await sandbox.kill()
```

```bash CLI icon="terminal" theme={"system"}
# Build a template from a Dockerfile, then create a sandbox and run a command
novita template create example-python-template --dockerfile ./novita.Dockerfile
sandbox_id=$(novita sandbox create example-python-template -d)
novita sandbox exec "$sandbox_id" -- python --version
novita sandbox kill "$sandbox_id"
```

## Tag a release

```python Python icon="python" theme={"system"}
from novita_sandbox import Novita

novita = Novita()

template = novita.template.new().from_python_image("3.12")
build = novita.template.build(template, "my-template", tags=["latest", "stable"])

novita.template.assign_tags("my-template:v1.0", "production")
```

```js JavaScript & TypeScript icon="js" theme={"system"}
import { Novita } from 'novita-sandbox'

const novita = new Novita()

const template = novita.template.new().fromPythonImage('3.12')
const build = await novita.template.build(template, 'my-template', {
  tags: ['latest', 'stable'],
})

await novita.template.assignTags('my-template:v1.0', 'production')
```

## Inspect templates

```python Python icon="python" theme={"system"}
from novita_sandbox import Novita

novita = Novita()
res = novita.template.list(template_type="template_build", page=1, limit=5)

for item in res.items:
    print(item.template_id, item.aliases, item.cpu_count, item.memory_mb)
```

```js JavaScript & TypeScript icon="js" theme={"system"}
import { Novita } from 'novita-sandbox'

const novita = new Novita()
const paginator = novita.template.list({ templateType: 'template_build', limit: 5 })
const page = await paginator.nextPage()

for (const item of page.templates) {
  console.log(item.templateId, item.aliases, item.cpuCount, item.memoryMB)
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.