Skip to content

Runtime Registry

The runtime registry defines how each programming language is executed inside Kubernetes pods. It maps language/version pairs to Docker images, file extensions, and interpreter commands. Adding a new language or version is a matter of extending the specification dictionary.

Supported Languages

Language Versions Image Template File Extension
Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 python:{version}-slim .py
Node.js 18, 20, 22 node:{version}-alpine .js
Ruby 3.1, 3.2, 3.3 ruby:{version}-alpine .rb
Go 1.20, 1.21, 1.22 golang:{version}-alpine .go
Bash 5.1, 5.2, 5.3 bash:{version} .sh

Language Specification

Each language is defined by a LanguageSpec dictionary containing the available versions, Docker image template, file extension, and interpreter command:

class LanguageSpec(TypedDict):
    versions: list[str]
    image_tpl: str
    file_ext: str
    interpreter: list[str]

The full specification for all languages:

LANGUAGE_SPECS: dict[str, LanguageSpec] = {
    "python": {
        "versions": ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"],
        "image_tpl": "python:{version}-slim",
        "file_ext": "py",
        "interpreter": ["python"],
    },
    "node": {
        "versions": ["18", "20", "22"],
        "image_tpl": "node:{version}-alpine",
        "file_ext": "js",
        "interpreter": ["node"],
    },
    "ruby": {
        "versions": ["3.1", "3.2", "3.3"],
        "image_tpl": "ruby:{version}-alpine",
        "file_ext": "rb",
        "interpreter": ["ruby"],
    },
    "bash": {
        "versions": ["5.1", "5.2", "5.3"],
        "image_tpl": "bash:{version}",
        "file_ext": "sh",
        "interpreter": ["bash"],
    },
    "go": {
        "versions": ["1.20", "1.21", "1.22"],
        "image_tpl": "golang:{version}-alpine",
        "file_ext": "go",
        "interpreter": ["go", "run"],
    },
}

Runtime Configuration

The registry generates a RuntimeConfig for each language/version combination. This contains everything needed to run a script in a pod:

class RuntimeConfig(NamedTuple):
    image: str  # Full Docker image reference
    file_name: str  # Name that will be mounted under /scripts/
    command: list[str]  # Entrypoint executed inside the container
  • image: The full Docker image reference (e.g., python:3.11-slim)
  • file_name: The script filename mounted at /scripts/ (e.g., main.py)
  • command: The command to execute (e.g., ["python", "/scripts/main.py"])

Adding a New Language

To add support for a new programming language:

  1. Add an entry to LANGUAGE_SPECS with versions, image template, file extension, and interpreter
  2. Add an example script to EXAMPLE_SCRIPTS demonstrating version-specific features
  3. The _make_runtime_configs() function automatically generates runtime configs

For example, to add Rust support:

"rust": {
    "versions": ["1.75", "1.76", "1.77"],
    "image_tpl": "rust:{version}-slim",
    "file_ext": "rs",
    "interpreter": ["rustc", "-o", "/tmp/main", "{file}", "&&", "/tmp/main"],
}

The image template uses {version} as a placeholder, which gets replaced with each version number when generating the registry.

Example Scripts

Each language includes an example script that demonstrates both universal features and version-specific syntax. These scripts are shown in the frontend editor as templates:

EXAMPLE_SCRIPTS: dict[str, str] = {
    "python": """
# This f-string formatting works on all supported Python versions (3.7+)
py_version = "3.x"
print(f"Hello from a Python {py_version} script!")

# The following block uses Structural Pattern Matching,
# which was introduced in Python 3.10.
# THIS WILL CAUSE A SYNTAX ERROR ON VERSIONS < 3.10.

lang_code = 1
match lang_code:
    case 1:
        print("Structural Pattern Matching is available on this version (Python 3.10+).")
    case _:
        print("Default case.")

# Union types using | operator (Python 3.10+)
def process_data(value: int | str | None) -> str:
    if value is None:
        return "No value"
    return f"Got: {value}"

print(process_data(42))
print(process_data("hello"))
print(process_data(None))
""",

The example scripts intentionally use features that may not work on older versions, helping users understand version compatibility. For instance, Python's match statement (3.10+), Node's Promise.withResolvers() (22+), and Go's clear() function (1.21+).

API Endpoints

The runtime information is available via two endpoints:

GET /api/v1/k8s-limits

Returns resource limits and supported runtimes:

{
  "cpu_limit": "1000m",
  "memory_limit": "128Mi",
  "cpu_request": "1000m",
  "memory_request": "128Mi",
  "execution_timeout": 300,
  "supported_runtimes": {
    "python": {"versions": ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"], "file_ext": "py"},
    "node": {"versions": ["18", "20", "22"], "file_ext": "js"},
    "ruby": {"versions": ["3.1", "3.2", "3.3"], "file_ext": "rb"},
    "go": {"versions": ["1.20", "1.21", "1.22"], "file_ext": "go"},
    "bash": {"versions": ["5.1", "5.2", "5.3"], "file_ext": "sh"}
  }
}

GET /api/v1/example-scripts

Returns example scripts for each language:

{
  "scripts": {
    "python": "# Python example script...",
    "node": "// Node.js example script...",
    "ruby": "# Ruby example script...",
    "go": "package main...",
    "bash": "#!/bin/bash..."
  }
}

Key Files

File Purpose
runtime_registry.py Language specifications and runtime config generation
api/routes/execution.py API endpoints including k8s-limits and example-scripts