{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/shardflux-dev/json-schema/shardflux-dev-template-recipe-v2-schema.json",
  "title": "Template recipe v2 (shardflux.template-recipe.v2)",
  "description": "A template without a Dockerfile (docs/INTEGRATION_CONTRACTS.md): `build` changes the filesystem through the host builder's structured steps, `settings` goes into the manifest and applies when a workspace opens. This document is the body field `recipe` of POST …/template-builds, the `recipe` of GET …/templates/{slug}/versions/{v}/recipe (export), and the content of template.yaml (the same document in YAML; only clients parse YAML). In template.yaml a file entry may name a local path (`from`) instead of an upload; clients upload it and send `upload` (the API refuses `from`). Rules JSON Schema cannot express, enforced by the API with 422 validation_failed and details.reason (): input names are unique across settings.env and settings.inputs; a secret input has no default; a required input has no default; start command names are unique; `to` is not platform-owned; build.network.allow_hosts only with build \"allowlist\" and extra_hosts only with \"auto\"; the sum of every run/command script is at most 262144 bytes; start timeout_seconds sum to at most 3600; languages are in the API's language table for the base; services need a base whose guest agent has services.v1; immutable paths are not platform-owned, do not contain a platform-owned path and do not nest.",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/shardflux-dev-openapi.json#/components/schemas/TemplateRecipeV2",
  "type": "object",
  "required": [
    "schema",
    "base",
    "build",
    "settings"
  ],
  "additionalProperties": false,
  "properties": {
    "schema": {
      "enum": [
        "shardflux.template-recipe.v2"
      ]
    },
    "base": {
      "description": "`<template slug>@<version>`: a published, non-archived, layered-capable version this organization can use (its own templates first, then platform), e.g. ubuntu-24.04@1.",
      "type": "string",
      "minLength": 3,
      "maxLength": 120,
      "pattern": "^[a-z0-9](?:[a-z0-9._-]{0,98}[a-z0-9])?@[1-9][0-9]{0,8}$"
    },
    "build": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "languages": {
          "description": "Languages from the API's language table. version omitted = the table's default for the base. Compiled first, in the table's order (not this array's).",
          "type": "array",
          "maxItems": 8,
          "items": {
            "type": "object",
            "required": [
              "id"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "enum": [
                  "python",
                  "node",
                  "go",
                  "rust",
                  "java"
                ]
              },
              "version": {
                "type": "string",
                "pattern": "^[0-9]+(\\.[0-9]+){0,2}$"
              }
            }
          }
        },
        "packages": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "apt": {
              "type": "array",
              "maxItems": 256,
              "items": {
                "description": "A plain package spec (the builder's pkgRE, not starting with '-').",
                "type": "string",
                "pattern": "^[A-Za-z0-9@][A-Za-z0-9@._+:/=<>~!,\\[\\]-]{0,213}$"
              }
            },
            "pip": {
              "description": "Installed into /opt/venv (implies the python language).",
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "packages": {
                  "type": "array",
                  "maxItems": 256,
                  "items": {
                    "description": "A plain package spec (the builder's pkgRE, not starting with '-').",
                    "type": "string",
                    "pattern": "^[A-Za-z0-9@][A-Za-z0-9@._+:/=<>~!,\\[\\]-]{0,213}$"
                  }
                },
                "requirements": {
                  "description": "Absolute paths of requirements files inside the template (usually from files[]), installed with pip -r.",
                  "type": "array",
                  "maxItems": 16,
                  "items": {
                    "description": "Absolute, clean (no '.', '..', '//' or trailing '/'), at most 1024 bytes.",
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 1024,
                    "pattern": "^(/[^/\\x00\\r\\n]+)+$"
                  }
                }
              }
            },
            "npm": {
              "description": "npm install -g (implies the node language unless the base has node).",
              "type": "array",
              "maxItems": 256,
              "items": {
                "description": "A plain package spec (the builder's pkgRE, not starting with '-').",
                "type": "string",
                "pattern": "^[A-Za-z0-9@][A-Za-z0-9@._+:/=<>~!,\\[\\]-]{0,213}$"
              }
            }
          }
        },
        "files": {
          "description": "Uploaded files and folders, applied in this order (a later entry overwrites an earlier one).",
          "type": "array",
          "maxItems": 1000,
          "items": {
            "type": "object",
            "required": [
              "kind",
              "to"
            ],
            "additionalProperties": false,
            "properties": {
              "upload": {
                "description": "An upload of this organization: sha256:<64 lower-case hex>.",
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "from": {
                "description": "template.yaml only: a local file (kind file) or directory (kind tar) the client uploads. Refused by the API.",
                "type": "string",
                "minLength": 1,
                "maxLength": 4096
              },
              "kind": {
                "enum": [
                  "file",
                  "tar"
                ]
              },
              "to": {
                "description": "kind file: the file's path; kind tar: the directory the archive is extracted into. Platform-owned paths are refused.",
                "type": "string",
                "minLength": 2,
                "maxLength": 1024,
                "pattern": "^(/[^/\\x00\\r\\n]+)+$"
              },
              "owner": {
                "description": "Default root.",
                "type": "string",
                "pattern": "^([a-z_][a-z0-9_-]{0,31}|[0-9]{1,10})(:([a-z_][a-z0-9_-]{0,31}|[0-9]{1,10}))?$"
              },
              "mode": {
                "description": "Octal permission bits of a file (default 0644); absent or null for kind tar.",
                "oneOf": [
                  {
                    "type": "null"
                  },
                  {
                    "type": "string",
                    "pattern": "^0?[0-7]{3}$"
                  }
                ]
              }
            }
          }
        },
        "steps": {
          "description": "Named build scripts, run in this order after languages, apt, files, pip and npm.",
          "type": "array",
          "maxItems": 64,
          "items": {
            "type": "object",
            "required": [
              "name",
              "run"
            ],
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z0-9][a-z0-9._-]{0,62}$"
              },
              "run": {
                "description": "Shell script run by /bin/bash -euo pipefail -c; 1..65536 bytes, no NUL.",
                "type": "string",
                "minLength": 1,
                "maxLength": 65536,
                "pattern": "^[^\\x00]+$"
              },
              "user": {
                "description": "Default root.",
                "type": "string",
                "pattern": "^([a-z_][a-z0-9_-]{0,31}|[0-9]{1,10})$"
              },
              "cwd": {
                "oneOf": [
                  {
                    "type": "null"
                  },
                  {
                    "description": "Absolute, clean (no '.', '..', '//' or trailing '/'), at most 1024 bytes.",
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 1024,
                    "pattern": "^(/[^/\\x00\\r\\n]+)+$"
                  }
                ]
              },
              "env": {
                "type": "object",
                "maxProperties": 64,
                "propertyNames": {
                  "description": "POSIX-style environment name; the SHARDFLUX_ prefix is reserved.",
                  "type": "string",
                  "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
                },
                "additionalProperties": {
                  "description": "At most 4096 bytes (UTF-8), no NUL, CR or LF.",
                  "type": "string",
                  "maxLength": 4096,
                  "pattern": "^[^\\x00\\r\\n]*$"
                }
              }
            }
          }
        },
        "network": {
          "description": "Build network. auto (default): hosts derived from the recipe plus extra_hosts; none: no egress; allowlist: exactly allow_hosts.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "build": {
              "enum": [
                "auto",
                "none",
                "allowlist"
              ]
            },
            "extra_hosts": {
              "type": "array",
              "maxItems": 50,
              "items": {
                "description": "A public DNS name (example.com) or one-label wildcard (*.example.com); no IP literals, no localhost/.local/.internal.",
                "type": "string",
                "minLength": 1,
                "maxLength": 255,
                "pattern": "^(\\*\\.)?[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+\\.?$"
              }
            },
            "allow_hosts": {
              "type": "array",
              "maxItems": 50,
              "items": {
                "description": "A public DNS name (example.com) or one-label wildcard (*.example.com); no IP literals, no localhost/.local/.internal.",
                "type": "string",
                "minLength": 1,
                "maxLength": 255,
                "pattern": "^(\\*\\.)?[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+\\.?$"
              }
            }
          }
        }
      }
    },
    "settings": {
      "description": "What a workspace of the version gets when it opens (). Omitted fields are empty (recipes do not carry settings forward).",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "data_mounts": {
          "description": "Workspace-private Ext4 data mounts; requires policy.template_data_mounts and guest feature template_data_mounts.v1.",
          "type": "array",
          "maxItems": 4,
          "items": {
            "type": "object",
            "required": [
              "path"
            ],
            "additionalProperties": false,
            "properties": {
              "path": {
                "type": "string",
                "minLength": 2,
                "maxLength": 255,
                "pattern": "^/[A-Za-z0-9_./-]+$"
              }
            }
          }
        },
        "env": {
          "description": "Template environment for every exec, PTY, start command and service (below text inputs and the call's env).",
          "type": "object",
          "maxProperties": 128,
          "propertyNames": {
            "description": "POSIX-style environment name; the SHARDFLUX_ prefix is reserved.",
            "type": "string",
            "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
          },
          "additionalProperties": {
            "description": "At most 4096 bytes (UTF-8), no NUL, CR or LF.",
            "type": "string",
            "maxLength": 4096,
            "pattern": "^[^\\x00\\r\\n]*$"
          }
        },
        "inputs": {
          "description": "Open-time inputs. text: a value passed to open({inputs}); secret: a stored secret of the same name, bound to the workspace.",
          "type": "object",
          "maxProperties": 32,
          "propertyNames": {
            "description": "POSIX-style environment name; the SHARDFLUX_ prefix is reserved.",
            "type": "string",
            "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
          },
          "additionalProperties": {
            "type": "object",
            "required": [
              "kind"
            ],
            "additionalProperties": false,
            "properties": {
              "kind": {
                "enum": [
                  "text",
                  "secret"
                ]
              },
              "required": {
                "type": "boolean",
                "description": "Default: false."
              },
              "default": {
                "description": "text inputs only.",
                "type": [
                  "null",
                  "string"
                ],
                "maxLength": 4096,
                "pattern": "^[^\\x00\\r\\n]*$"
              },
              "description": {
                "type": [
                  "null",
                  "string"
                ],
                "maxLength": 500
              }
            }
          }
        },
        "start": {
          "description": "Start commands: create = on a new workspace layer, boot = every cold boot, resume = every memory restore.",
          "type": "array",
          "maxItems": 32,
          "items": {
            "type": "object",
            "required": [
              "name",
              "when",
              "run"
            ],
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z0-9][a-z0-9._-]{0,62}$"
              },
              "when": {
                "enum": [
                  "create",
                  "boot",
                  "resume"
                ]
              },
              "run": {
                "description": "Shell script run by /bin/bash -euo pipefail -c; 1..65536 bytes, no NUL.",
                "type": "string",
                "minLength": 1,
                "maxLength": 65536,
                "pattern": "^[^\\x00]+$"
              },
              "user": {
                "oneOf": [
                  {
                    "type": "null"
                  },
                  {
                    "description": "A user name or numeric uid of the template (the builder's userRE without a group).",
                    "type": "string",
                    "pattern": "^([a-z_][a-z0-9_-]{0,31}|[0-9]{1,10})$"
                  }
                ],
                "description": "Absent or null: the template's default user."
              },
              "cwd": {
                "oneOf": [
                  {
                    "type": "null"
                  },
                  {
                    "description": "Absolute, clean (no '.', '..', '//' or trailing '/'), at most 1024 bytes.",
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 1024,
                    "pattern": "^(/[^/\\x00\\r\\n]+)+$"
                  }
                ]
              },
              "timeout_seconds": {
                "type": "integer",
                "minimum": 1,
                "maximum": 1800,
                "description": "Default: 300."
              }
            }
          }
        },
        "services": {
          "description": "Processes kept running by the guest; ready before open() returns.",
          "type": "object",
          "maxProperties": 16,
          "propertyNames": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{0,62}$"
          },
          "additionalProperties": {
            "type": "object",
            "required": [
              "run"
            ],
            "additionalProperties": false,
            "properties": {
              "run": {
                "description": "Shell script run by /bin/bash -euo pipefail -c; 1..65536 bytes, no NUL.",
                "type": "string",
                "minLength": 1,
                "maxLength": 65536,
                "pattern": "^[^\\x00]+$"
              },
              "user": {
                "oneOf": [
                  {
                    "type": "null"
                  },
                  {
                    "description": "A user name or numeric uid of the template (the builder's userRE without a group).",
                    "type": "string",
                    "pattern": "^([a-z_][a-z0-9_-]{0,31}|[0-9]{1,10})$"
                  }
                ],
                "description": "Absent or null: the template's default user."
              },
              "cwd": {
                "oneOf": [
                  {
                    "type": "null"
                  },
                  {
                    "description": "Absolute, clean (no '.', '..', '//' or trailing '/'), at most 1024 bytes.",
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 1024,
                    "pattern": "^(/[^/\\x00\\r\\n]+)+$"
                  }
                ]
              },
              "restart": {
                "enum": [
                  "always",
                  "on_failure",
                  "never"
                ],
                "description": "Default: \"on_failure\"."
              },
              "ready": {
                "oneOf": [
                  {
                    "type": "null"
                  },
                  {
                    "type": "object",
                    "required": [
                      "port"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "port": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 65535
                      }
                    }
                  },
                  {
                    "type": "object",
                    "required": [
                      "command"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "command": {
                        "description": "Shell script run by /bin/bash -euo pipefail -c; 1..65536 bytes, no NUL.",
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 65536,
                        "pattern": "^[^\\x00]+$"
                      }
                    }
                  }
                ]
              },
              "initialized_cpu": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "compatibility",
                  "reset",
                  "timeout_seconds"
                ],
                "properties": {
                  "compatibility": {
                    "enum": [
                      "cpu-service-v1",
                      "cpu-service-fresh-inputs-v1"
                    ]
                  },
                  "reset": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536
                  },
                  "timeout_seconds": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 30
                  },
                  "fresh_env_names": {
                    "type": "array",
                    "maxItems": 64,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "pattern": "^[A-Z_][A-Z0-9_]{0,63}$"
                    }
                  }
                }
              },
              "ready_timeout_seconds": {
                "type": "integer",
                "minimum": 1,
                "maximum": 600,
                "description": "Default: 60."
              }
            }
          }
        },
        "defaults": {
          "description": "Manifest defaults (). agent_tools stays reserved (null).",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "lifetime": {
              "enum": [
                "persistent",
                "session"
              ]
            },
            "idle_timeout_seconds": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "integer",
                  "minimum": 60,
                  "maximum": 86400
                }
              ]
            },
            "limits": {
              "description": "Ceilings enforced at admission (clamped).",
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "object",
                  "required": [
                    "cpu_millis_ceiling",
                    "memory_mib_ceiling",
                    "disk_gib"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "cpu_millis_ceiling": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 1000000
                    },
                    "memory_mib_ceiling": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 16777216
                    },
                    "disk_gib": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 1000000
                    }
                  }
                }
              ]
            },
            "egress": {
              "description": "Workspace network ceiling: internet = no ceiling (stored as null), allowlist = only allow_hosts (TCP, any port), none = no egress.",
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "object",
                  "required": [
                    "mode"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "mode": {
                      "enum": [
                        "internet",
                        "allowlist",
                        "none"
                      ]
                    },
                    "allow_hosts": {
                      "type": "array",
                      "maxItems": 50,
                      "items": {
                        "description": "A public DNS name (example.com) or one-label wildcard (*.example.com); no IP literals, no localhost/.local/.internal.",
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "pattern": "^(\\*\\.)?[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+\\.?$"
                      }
                    }
                  }
                }
              ]
            },
            "agent_tools": {
              "type": "null"
            }
          }
        }
      }
    },
    "immutable": {
      "description": "Directories every workspace of the template mounts read-only from the template's newest published version: workspaces pick up a newer version when they cold-boot or resume. Not `/`, not equal to or under /proc, /sys, /dev, /run, /tmp, /lost+found or a platform-owned path, not containing a platform-owned path, none equal to or containing another (422 invalid_path). Omitted: the list of the template's newest published version. A version keeps every path of that list (422 immutable_path_removed) and a non-empty list needs a base whose guest agent has immutable_paths.v1 (422 immutable_paths_unsupported_base). Each path is a directory in the built filesystem.",
      "type": "array",
      "maxItems": 8,
      "uniqueItems": true,
      "items": {
        "description": "Absolute, clean (no '.', '..', '//' or trailing '/'), at most 256 bytes, no control characters.",
        "type": "string",
        "minLength": 2,
        "maxLength": 256,
        "pattern": "^(/[^/\\x00-\\x1f\\x7f-\\x9f]+)+$"
      }
    },
    "resources": {
      "description": "Builder VM bounds, exactly as recipe v1 `resources` (not part of recipe_sha256).",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "cpu_millis": {
          "type": "integer",
          "minimum": 500,
          "maximum": 16000
        },
        "memory_mib": {
          "type": "integer",
          "minimum": 512,
          "maximum": 32768,
          "multipleOf": 2
        },
        "disk_gib": {
          "type": "integer",
          "minimum": 1,
          "maximum": 200
        },
        "timeout_seconds": {
          "type": "integer",
          "minimum": 60,
          "maximum": 86400
        }
      }
    }
  }
}