Skip to main content
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.
name
string
required
A unique name for the template.
dockerfile
string
required
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.
name
string
required
Template name.
Returns: Promise<TemplateInfo>

Deleting a Template

await sandbox.templates.delete('python-ml');

sandbox.templates.delete(name)

Deletes a template by name.
name
string
required
Template name to delete.
Returns: Promise<void>

TemplateInfo

FieldTypeDescription
templateIDstringUnique template identifier
namestringTemplate name
tagstringImage tag
statusstringBuild 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