Templates let you create reusable sandbox images from Dockerfiles. Pre-install languages, tools, and dependencies so your sandboxes start ready to go.
Building a Template
import { Sandbox } from 'opensandbox';
const sandbox = await Sandbox.create();
const template = await sandbox.templates.build('python-ml', `
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip3 install numpy pandas scikit-learn
`);
console.log(template.templateID); // tpl-abc123
console.log(template.status); // building → ready
sandbox.templates.build(name, dockerfile)
Builds a new template from a Dockerfile.
A unique name for the template.
The Dockerfile content to build from.
Returns: Promise<TemplateInfo>
Listing Templates
const templates = await sandbox.templates.list();
for (const t of templates) {
console.log(`${t.name} (${t.tag}) — ${t.status}`);
}
sandbox.templates.list()
Returns all templates.
Returns: Promise<TemplateInfo[]>
Getting a Template
const template = await sandbox.templates.get('python-ml');
console.log(template);
sandbox.templates.get(name)
Gets a template by name.
Returns: Promise<TemplateInfo>
Deleting a Template
await sandbox.templates.delete('python-ml');
sandbox.templates.delete(name)
Deletes a template by name.
Returns: Promise<void>
TemplateInfo
| Field | Type | Description |
|---|
templateID | string | Unique template identifier |
name | string | Template name |
tag | string | Image tag |
status | string | Build status: "building", "ready", "error" |
Using a Template
Once built, pass the template name when creating a sandbox:
const sandbox = await Sandbox.create({ template: 'python-ml' });
const result = await sandbox.commands.run('python3 -c "import numpy; print(numpy.__version__)"');
console.log(result.stdout); // 1.24.0