ScaleBox Docs

Template API

Complete API reference for managing environment templates. Templates define the base images and configurations used to create sandbox environments in ScaleBox.

Authentication Required: All API requests require authentication using the X-API-Key header with your API key.

Template Concepts

Templates in ScaleBox are pre-configured environment definitions that serve as the foundation for creating sandbox environments. They define the base image, default resource allocations, and metadata that will be used when users create new sandboxes.

Template Components

  • Base Image - Harbor registry image with pre-installed software and configurations
  • Resource Defaults - Default CPU, memory, and storage allocations for sandboxes
  • Metadata - JSON metadata describing template capabilities and use cases
  • Access Control - Public/private visibility and ownership permissions

Template Name Validation

Template names are validated strictly so they work as identifiers (e.g. in sandbox creation and image paths). The same rules apply when creating or updating a template and when providing new_name for share.

  • Length: 4–32 characters
  • Characters: Only lowercase letters (a–z), numbers (0–9), hyphens (-), and underscores (_)
  • Start and end: Must start and end with an alphanumeric character (letter or digit)
  • Cannot start with a number
  • No consecutive separators: No --, __, -_, or _-
  • Cannot start with tpl- (reserved for system template IDs)
  • Reserved words (exact match, case-insensitive): admin, root, system, scalebox, harbor, docker, k8s, kubernetes, api, www, mail, ftp, ssh, public, private, test, dev, prod, staging, local, localhost, example, sample

Invalid examples: My Nginx (uppercase and space), nginx (too short), tpl-my-app (reserved prefix), my--app (consecutive hyphens)

Valid examples: my-nginx, python-data-science, node_web_app

Template Statuses

Templates progress through different statuses during their lifecycle:

StatusDescription
pendingTemplate has been created but build process has not started
buildingTemplate image is being built from source
pushingTemplate image is being pushed to Harbor registry
availableTemplate is ready for use in sandbox creation
failedTemplate build or push process failed

Template Access Control

Template access is controlled by ownership and visibility settings:

TypeDescription
Public TemplatesAccessible to all authenticated users, typically created by admin users
Private TemplatesAccessible only to the owner and root users in the same account
Account TemplatesAccessible to all users in the same account (root user templates)

API Endpoints

List Templates

GET /v1/templates

List all accessible templates for the authenticated user.

Request Parameters

NameTypeRequiredDescription
statusstringNoFilter templates by status (pending, building, pushing, available, failed)
visibilitystringNoFilter templates by visibility (private, account_shared, public)
namestringNoExact template name match (e.g. for resolving by name)
usablestringNoSet to 'true' to return only templates usable for sandbox creation

Example

curl -X GET https://api.scalebox.dev/v1/templates \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678"

Get Template

GET /v1/templates/{template_id}

Get detailed information about a specific template.

Example

curl -X GET https://api.scalebox.dev/v1/templates/tpl-abc123def456789 \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678"

Create Template

POST /v1/templates

Create a new template (ScaleBox-family or custom). Full validation applies: name uniqueness, budget, subscription limits, and for custom external images pre-validation.

Request Parameters

NameTypeRequiredDefaultDescription
namestringYes-Template name. Must follow Template Name Validation rules
descriptionstringNo-Detailed description of the template
default_cpu_countintegerNo2Default CPU cores for sandboxes using this template
default_memory_mbintegerNo512Default memory in MB for sandboxes using this template
visibilitystringNoprivateTemplate visibility: 'private', 'account_shared', or 'public' (admin only)
template_sourcestringNoscalebox_family'scalebox_family' (default) or 'custom'
custom_image_sourcestringNo-Required if template_source is 'custom': 'external' or 'imported'
external_image_urlstringNo-Required for custom external templates. Full image URL
external_registry_usernamestringNo-Optional registry username for private external images
external_registry_passwordstringNo-Optional registry password for private external images
harbor_image_urlstringNo-Full Harbor image URL
harbor_projectstringNoAuto-generatedHarbor project name
harbor_repositorystringNo-Harbor repository name
harbor_tagstringNolatestHarbor image tag
metadatastringNoJSON metadata for the template
base_template_idstringNo-Template ID to inherit from (same template_source only)
portsstringNo[]JSON array of port configurations
reset_portsbooleanNofalseIf true, remove unprotected ports inherited from base
custom_commandstringNo-Custom startup command for the container
ready_commandstringNo-Readiness probe: JSON with type (exec/httpGet/tcpSocket)

Example

curl -X POST https://api.scalebox.dev/v1/templates \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "python-data-science",
    "description": "Python environment with data science libraries",
    "default_cpu_count": 2,
    "default_memory_mb": 4096,
    "harbor_project": "scalebox-public",
    "harbor_repository": "python-data-science",
    "harbor_tag": "latest",
    "metadata": {
      "category": "data-science",
      "languages": ["python"],
      "frameworks": ["pandas", "numpy", "scikit-learn"]
    }
  }'

Update Template

PUT /v1/templates/{template_id}

Update template configuration and Harbor information.

Example

curl -X PUT https://api.scalebox.dev/v1/templates/tpl-abc123def456789 \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Updated Python environment with latest libraries",
    "default_memory_mb": 8192
  }'

Delete Template

DELETE /v1/templates/{template_id}

Delete a template and its Harbor image.

Example

curl -X DELETE https://api.scalebox.dev/v1/templates/tpl-abc123def456789 \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678"

Register Template

POST /v1/templates/register

Register an existing Harbor image as a template. Use when the image already exists in Harbor (e.g. after CLI build/push). Creates a private, scalebox_family template only.

Request Parameters

NameTypeRequiredDescription
namestringYesTemplate name
descriptionstringNoDetailed description of the template
default_cpu_countintegerNoDefault CPU cores
default_memory_mbintegerNoDefault memory in MB
harbor_image_urlstringNoFull Harbor image URL
harbor_projectstringNoHarbor project name
harbor_repositorystringNoHarbor repository name
harbor_tagstringNoHarbor image tag

Example

curl -X POST https://api.scalebox.dev/v1/templates/register \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "existing-image-template",
    "description": "Template for existing Harbor image",
    "harbor_project": "my-project",
    "harbor_repository": "my-app",
    "harbor_tag": "v1.0.0"
  }'

Update Template Status

PUT /v1/templates/{template_id}/status

Update template build status and tracking information.

Request Parameters

NameTypeRequiredDescription
statusstringYesTemplate status (pending, building, pushing, available, failed)
error_messagestringNoError message if status is failed
push_logsstringNoBuild and push logs
harbor_image_urlstringNoUpdated Harbor image URL

Validate Template

POST /v1/templates/{template_id}/validate

Validate and activate a template with Harbor image.

Request Parameters

NameTypeRequiredDescription
harbor_image_urlstringYesHarbor image URL to validate

Get Storage Usage

GET /v1/templates/storage-usage

Get private template storage usage statistics.

Example

curl -X GET https://api.scalebox.dev/v1/templates/storage-usage \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678"

Response

{
  "used_gb": 2.5,
  "limit_gb": 5.0,
  "percentage": 50.0
}

List Import Jobs

GET /v1/import-jobs

List template import jobs for the current user.

Request Parameters

NameTypeRequiredDescription
statusstringNoFilter: ongoing (default), pending, running, completed, failed, cancelled
template_idstringNoFilter jobs for this template ID
limitintegerNoMax jobs to return (1-100)
offsetintegerNoPagination offset

Get Import Job

GET /v1/import-jobs/{job_id}

Get a single import job by job ID.

Share Template

POST /v1/templates/{template_id}/share

Share a private template with your account (visibility → account_shared). Only template owner or admin.

Request Parameters

NameTypeRequiredDescription
new_namestringNoOptional new name when sharing

Example

curl -X POST https://api.scalebox.dev/v1/templates/tpl-abc123def456789/share \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{}'

Unshare Template

POST /v1/templates/{template_id}/unshare

Make an account-shared template private again. Only template owner or admin.

Example

curl -X POST https://api.scalebox.dev/v1/templates/tpl-abc123def456789/unshare \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{}'

Create vs Register

AspectPOST /v1/templates (Create)POST /v1/templates/register (Register)
PurposeCreate any template (ScaleBox or custom)Record an existing Harbor image as a template
Template typesscalebox_family or custom (external/imported)scalebox_family only
VisibilityRequest chooses (admin can set public)Always private
Name validationFull template name rules + uniquenessRecommend same rules for consistency

Harbor Integration

Templates are tightly integrated with Harbor container registry for image storage and management:

Harbor Project Structure

  • Public Templates: Stored in scalebox-public project
  • Private Templates: Stored in user-specific projects like scalebox-{user_id}
  • Admin Templates: Can be stored in any project, including scalebox-public

Image Management

  • Automatic Size Detection: Template image sizes are automatically retrieved from Harbor
  • Storage Tracking: Private template storage usage is tracked and limited
  • Cleanup: Deleting templates automatically removes Harbor images and repositories

Error Handling

ScenarioDescription
Template Name ValidationTemplate names must follow the Template Name Validation rules
Access ControlUsers can only access public templates and their own private templates
Template UsageTemplates cannot be deleted if they are being used by active sandboxes

Best Practices

PracticeDescription
Template NamingUse names that pass validation: lowercase, 4–32 characters
Resource DefaultsSet appropriate default CPU and memory based on typical usage patterns
Metadata UsageInclude rich metadata to help users discover and understand template capabilities

HTTP Status Codes

CodeDescription
200Success
201Created
400Bad Request
401Unauthorized
403Forbidden
404Not Found
429Too Many Requests
500Internal Server Error

On this page