Listing Templates
Copy
import { RunTools } from '@runtools/sdk';
const rt = new RunTools({ apiKey: process.env.RUNTOOLS_API_KEY });
// List all templates
const templates = await rt.templates.list();
// List system templates
const system = await rt.templates.list({ type: 'system' });
// List your custom templates
const custom = await rt.templates.list({ type: 'custom' });
Creating Templates
Using Template Builder
Copy
const template = await rt.templates.create({
slug: 'my-fullstack',
name: 'Full Stack Environment',
// Base OS
os: 'ubuntu-24.04',
// Runtimes
runtimes: [
{ name: 'node', version: '20' },
{ name: 'python', version: '3.12' },
],
// System packages
apt: ['postgresql-client', 'redis-tools', 'ffmpeg'],
// Language packages
npm: ['typescript', 'tsx', 'prettier'],
pip: ['numpy', 'pandas', 'requests'],
// Environment variables
env: {
NODE_ENV: 'development',
PYTHONUNBUFFERED: '1',
},
});
Using Dockerfile
Copy
const template = await rt.templates.create({
slug: 'my-custom',
name: 'Custom Environment',
dockerfile: `
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y \\
curl wget git nodejs npm python3 python3-pip
RUN npm install -g typescript tsx
WORKDIR /workspace
`,
});
Build Process
Copy
// Create template (starts build)
const template = await rt.templates.create({ ... });
console.log(template.status); // 'building'
// Stream build logs
for await (const line of template.buildLogs()) {
console.log(line);
}
// Wait for build to complete
await template.waitForBuild();
console.log(template.status); // 'ready'
Validating Templates
Copy
// Validate before building
const validation = await rt.templates.validate({
os: 'ubuntu-24.04',
runtimes: [{ name: 'node', version: '20' }],
npm: ['react@18', 'next@14'],
});
console.log(validation.valid); // true
console.log(validation.estimatedSize); // '680MB'
console.log(validation.warnings); // []
Package Search
Copy
// Search npm packages
const npm = await rt.packages.search('npm', 'react');
// Search pip packages
const pip = await rt.packages.search('pip', 'torch');
// Search apt packages
const apt = await rt.packages.search('apt', 'ffmpeg');
// Get package versions
const versions = await rt.packages.versions('npm', 'react');
// → ['19.0.0', '18.2.0', '18.1.0', ...]
Managing Templates
Copy
// Get template
const template = await rt.templates.get('my-fullstack');
// Update template (triggers rebuild)
await template.update({
npm: ['typescript', 'tsx', 'eslint'],
});
// Delete template
await template.delete();
Using Templates
Copy
// Create sandbox from template
const sandbox = await rt.sandboxes.create({
template: 'my-fullstack',
});
// Assign to agent deployment
const deployment = await rt.deployments.create({
runtimeSlug: 'code-assistant',
templateSlug: 'my-fullstack',
apiSlug: 'my-bot',
});
Preview Dockerfile
Copy
// Preview generated Dockerfile without building
const preview = await rt.templates.preview({
os: 'ubuntu-24.04',
runtimes: [{ name: 'node', version: '20' }],
npm: ['typescript'],
});
console.log(preview.dockerfile);
Types
Copy
import type {
Template,
TemplateStatus,
TemplateConfig,
RuntimeConfig,
ValidationResult,
} from '@runtools/sdk';