Write a Recipe in your own repository
A Recipe is your own training, data processing, inference or evaluation code together with its declaration. It lives in your own Git repository: a local-only repository, or a public or private GitHub repository. You publish it with el, and a Job runs it on a Runner the platform maintains.
Runner and Recipe
| Runner | Recipe | |
|---|---|---|
| Maintained by | The platform | You |
| Declaration | runner.toml | recipe.toml |
| Entry file | main.sh | entrypoint.sh |
| Decides | Image, resources, network and the standard params image, command, timeout_seconds, max_retries | Job types, params, input slots and your code |
| Identity | NAMESPACE/NAME@FULL_COMMIT | envloop://recipes/NAMESPACE/NAME@<recipe-sha256> |
Every Recipe runs through the same call chain:
- The platform starts the Runner's
main.shand prepares the handoff files below. main.shrunsbash "$ENVLOOP_RECIPE_ROOT/entrypoint.sh". The executable bit is not needed.- Your
entrypoint.shruns your code.
| Variable | Content |
|---|---|
ENVLOOP_RECIPE_ROOT | Read-only directory holding the unpacked Recipe package |
ENVLOOP_JOB_FILE | JSON: job_id, trial_id, type and the resolved resources |
ENVLOOP_PARAMS_FILE | JSON: the merged and validated Recipe params |
ENVLOOP_INPUTS_FILE | JSON: each input slot's local path, uri and manifest_sha256 |
ENVLOOP_OUTPUT_DIR | Writable output directory |
Exit code 0 means success. Write $ENVLOOP_OUTPUT_DIR/result.json as {"status": "succeeded" | "failed", "metrics": {NAME: NUMBER}}; metrics is optional and holds finite numbers. A Train Recipe writes its checkpoints under $ENVLOOP_OUTPUT_DIR/checkpoints/.
Repository layout
recipe.toml and entrypoint.sh sit next to each other. They can be at the repository root:
hello-recipe/
├── recipe.toml
├── entrypoint.sh
├── src/hello/train.py
└── README.md # not packaged: not under [source].paths
Or in a subdirectory of a larger repository:
ml-monorepo/
├── recipes/hello/recipe.toml
├── recipes/hello/entrypoint.sh
└── training/hello/train.py
- Package contents. The package root holds
recipe.tomlandentrypoint.sh. The files selected by[source].pathskeep their paths relative to the repository root. For the monorepo above, writepaths = ["training/hello"]and runtraining/hello/train.pyfrom$ENVLOOP_RECIPE_ROOT/training/hello/train.py. - Selection.
pathslists files or directories.excludelists exact files already selected. Ignored and unselected files are never packaged. - Limits. Regular files only, without symlinks or submodules. At most 1000 files, 512 MiB per file and 1 GiB in total. Path parts use letters, digits,
_,.or-and do not start with.. - Git is required. The CLI publishes a commit, so the directory must be inside a Git repository with at least one commit. For a plain directory, run
git initand commit once; no remote is needed.
Python dependencies
The package holds only your files. Your code can use packages in two ways.
- Packages in the Runner image.
envloop/trainruns in a public PyTorch CUDA runtime image with Python, PyTorch and pip. The dry run shows the exact image inparams.image. To use another public image that already has your packages, setparams.image. - Install them in
entrypoint.sh. Commit a requirements file with pinned versions under[source].pathsand install it before starting your code:
python3 -m pip install --user --no-cache-dir -r "$ENVLOOP_RECIPE_ROOT/src/requirements.txt"
- Network. Installing needs outbound access, which the Runner decides;
envloop/trainallows it ([sandbox] allow_internet = true). On a Runner without network access the install fails. - Where packages go.
--userinstalls under$HOME, which is writable in every Trial; the image's own site-packages can be read-only, and the Trial may not run as root. If the image's Python refuses user installs, create a virtual environment under$HOMEinstead. - Time. Installation counts toward the Trial's
params.timeout_seconds. - No cache. Nothing is kept between Trials or Jobs, so every Trial installs again. Pin exact versions (
==) so that every Trial gets the same packages.
A complete example
This example trains a stand-in model on one Dataset input. It uses only the Python standard library.
schema_version = "envloop.recipe/v3"
[recipe]
name = "example-org/hello-recipe"
types = ["train"]
[runner]
name = "envloop/train"
abi = "envloop.recipe/1"
[source]
paths = ["src"]
[inputs.train_dataset]
kind = "dataset"
required = true
[params]
run_name = { type = "string", required = true, description = "Label written to result.json" }
max_steps = { type = "integer", default = 10, minimum = 1, maximum = 1000 }
seed = { type = "integer", default = 42, locked = true }
[params.optimizer]
type = "object"
[params.optimizer.properties.learning_rate]
type = "number"
default = 0.01
minimum = 0
maximum = 1
[params.optimizer.properties.warmup_steps]
type = "integer"
default = 0
minimum = 0
[recipe].nameis theNAMESPACE/NAMEof the Recipe URI.typeslists the Job types it supports:bench,sandbox,trainorinference.[runner]. The Runner it targets and the Recipe ABI.abiis alwaysenvloop.recipe/1.[source].pathsselects the packaged code.repositoryis optional: omit it for a local-only repository, as here, or setrepository = "https://github.com/OWNER/REPO"for a GitHub repository. It is recorded as provenance only; the platform never fetches it. The commit comes from the revision you publish, not from this file.[inputs.SLOT].kindisdataset,checkpointorartifact.train_datasetandeval_datasetare Datasets;checkpointandresume_from_checkpointare Checkpoints.[params]. Each param hastype, and optionallydefault,required,description,enum,minimum,maximumandlocked. Arequired = trueparam has no default and must be set for every Job. Alockedparam keeps its default. Anobjectparam lists its fields underpropertiesand accepts no other fields unlessadditional_properties = true.- Reserved names. The standard params
image,command,timeout_secondsandmax_retriesbelong to the platform and cannot be declared. When the Runner declares a param with the same name, the Recipe may only narrow it: the same type, a tighter range, anenumsubset, and the Runner's locks and required params kept. Otherwise the result isRECIPE_PARAM_CONFLICT.envloop/traindeclares only standard params. - Optional tables.
[outputs] fileslists other files the Recipe writes under$ENVLOOP_OUTPUT_DIR.[dependencies.SLOT]pins another published Recipe byuriandmanifest_sha256.
#!/usr/bin/env bash
# The Runner's main.sh runs this file as: bash "$ENVLOOP_RECIPE_ROOT/entrypoint.sh"
set -euo pipefail
for name in ENVLOOP_JOB_FILE ENVLOOP_PARAMS_FILE ENVLOOP_INPUTS_FILE; do
[[ -r "${!name:-}" ]] || { echo "missing handoff file $name" >&2; exit 64; }
done
[[ -d "${ENVLOOP_OUTPUT_DIR:-}" ]] || { echo "missing ENVLOOP_OUTPUT_DIR" >&2; exit 64; }
# The package is read-only; put the packaged src/ directory on the import path.
export PYTHONPATH="$ENVLOOP_RECIPE_ROOT/src${PYTHONPATH:+:$PYTHONPATH}"
exec python3 -m hello.train
"""A minimal training loop: read the EnvLoop handoff files, train, write result.json."""
import json
import os
import random
from pathlib import Path
def read(variable):
return json.loads(Path(os.environ[variable]).read_text())
def main():
job = read("ENVLOOP_JOB_FILE")
params = read("ENVLOOP_PARAMS_FILE")
inputs = read("ENVLOOP_INPUTS_FILE")
output = Path(os.environ["ENVLOOP_OUTPUT_DIR"])
dataset = Path(inputs["train_dataset"]["path"])
examples = sum(1 for path in dataset.rglob("*") if path.is_file())
print(f"{job['type']} trial {job['trial_id']}: {examples} dataset files", flush=True)
random.seed(params["seed"])
optimizer = params["optimizer"]
loss = 1.0
for step in range(1, params["max_steps"] + 1):
rate = optimizer["learning_rate"] * min(1.0, step / max(1, optimizer["warmup_steps"]))
loss *= 1 - rate * random.random() # stand-in for a real training step
print(f"step {step} loss {loss:.6f}", flush=True)
result = {"status": "succeeded", "metrics": {"loss": loss, "steps": params["max_steps"]}}
(output / "result.json").write_text(json.dumps(result))
print(f"{params['run_name']}: done", flush=True)
if __name__ == "__main__":
main()
Publish
Commit the files, preview the Recipe, then publish it:
git add recipe.toml entrypoint.sh src
git commit -m "Add the hello Recipe"
el recipe create --directory . --revision FULL_COMMIT --wait --json
The command returns {asset, operation}. With --wait, use asset.uri and asset.manifest_sha256 from the ready projection. Without it, retain operation.operation_id and observe the same publication. --revision must be a complete immutable source commit. The content-derived Recipe digest is distinct from that source commit; changes produce a new immutable identity. Only committed recipe.toml, entrypoint.sh and declared source files are packaged from the local repository; the platform does not clone private sources.
Publish through the SDK with client.recipes.create(directory=".", revision="FULL_COMMIT", wait=True). A new name is private; --visibility internal shares it within the workspace, and public changes require a platform administrator. See Recipes.
Run it in a Train Job
Save the Job spec as job.json, replacing the placeholders with a full Runner commit, the published Recipe digest and your own Dataset:
{
"schema": "envloop.job/v2",
"type": "train",
"runner": "envloop/train@<runner-commit>",
"recipe": "example-org/hello-recipe@<recipe-sha256>",
"inputs": {
"train_dataset": {"uri": "envloop://datasets/example-org/messages@1", "config": "default", "split": "train"}
},
"params": {"run_name": "first-run", "max_steps": 20, "optimizer": {"learning_rate": 0.05}},
"resources": {"gpus": 1, "gpu_type": "H100"}
}
runner.NAMESPACE/NAME@REVISION; a branch or tag is frozen to its full commit. The Runner Revision must declare[recipe] abi = "envloop.recipe/1"and listtrainin its types. Find one withel runner list --json.recipe.NAMESPACE/NAME@<recipe-sha256>, where the digest is the receipt'smanifest_sha256. Only a digest is accepted.params. Runner and Recipe params share one namespace; every key must be declared by the Runner or the Recipe. An object param is merged field by field, sooptimizer.warmup_stepskeeps its Recipe default here. The standard paramsimage,command,timeout_secondsandmax_retriesare set here too. The Trial reads the merged non-standard params fromENVLOOP_PARAMS_FILE.inputs. Each slot is{uri, config, split}for a Dataset. The platform resolves the content digest and checks that you can read it; the Trial finds the slot inENVLOOP_INPUTS_FILE.resources. What each Trial needs:cpus,memory_mb,storage_mb,gpus,gpu_type,shm_mb. Omitted values come from the Runner.
Preview the resolved spec
POST /v1/jobs/resolve merges the request without creating a Job. overrides is an optional partial spec for one-off changes; it cannot contain schema, type or profile.
jq -n --slurpfile spec job.json '{spec: $spec[0], overrides: {params: {max_steps: 50}}}' |
curl --fail-with-body --silent --show-error https://api.envloop.ai/v1/jobs/resolve \
-H "Authorization: Bearer $ENVLOOP_API_KEY" \
-H "X-Workspace-ID: $ENVLOOP_WORKSPACE_ID" -H "X-Project-ID: $ENVLOOP_PROJECT_ID" \
-H "Content-Type: application/json" --data @-
The response, abridged, shows every merged value and the layer it came from:
{
"schema": "envloop.resolved-job/v1",
"spec": {
"runner": "envloop/train@<runner-commit>",
"recipe": "example-org/hello-recipe@<recipe-sha256>",
"params": {
"run_name": "first-run", "max_steps": 50, "seed": 42,
"optimizer": {"learning_rate": 0.05, "warmup_steps": 0},
"image": "<runner-image>", "command": "bash main.sh", "timeout_seconds": 3600, "max_retries": 0
},
"repeat": 1
},
"field_sources": {
"params.run_name": "spec",
"params.max_steps": "overrides",
"params.seed": "recipe",
"params.optimizer.learning_rate": "spec",
"params.optimizer.warmup_steps": "recipe",
"params.image": "runner",
"params.max_retries": "platform"
},
"warnings": []
}
Layers apply from highest to lowest: overrides, profile (a named Profile the spec references), spec, recipe (the recipe.toml defaults), runner (the Runner defaults) and platform (fallbacks nothing else set, such as repeat = 1). A required param that no layer sets is refused with RECIPE_PARAM_REQUIRED or RUNNER_PARAM_REQUIRED; no layer invents a value for it.
Submit
Send the same body with a request_id to POST /v1/jobs:
jq -n --slurpfile spec job.json '{request_id: "hello-recipe-1", spec: $spec[0]}' |
curl --fail-with-body --silent --show-error https://api.envloop.ai/v1/jobs \
-H "Authorization: Bearer $ENVLOOP_API_KEY" \
-H "X-Workspace-ID: $ENVLOOP_WORKSPACE_ID" -H "X-Project-ID: $ENVLOOP_PROJECT_ID" \
-H "Content-Type: application/json" --data @-
el job submit and the SDK do not send envloop.job/v2 requests yet; use the HTTP API. Read the Job with el job get JOB_ID, el job log JOB_ID --follow and el job result JOB_ID. Retry an uncertain submission with the same request_id and identical body.
Common errors
| Code | Cause | Fix |
|---|---|---|
RECIPE_DECLARATION_NOT_FOUND | No recipe.toml in --directory at that revision | Commit it, or point --directory at the directory that holds it |
RECIPE_ENTRYPOINT_NOT_FOUND | No entrypoint.sh next to recipe.toml | Commit entrypoint.sh in the same directory |
RECIPE_PACKAGE_UNCOMMITTED | Packaged paths differ from the branch or tag | Commit or remove the changes, or pass a full commit |
RECIPE_REVISION_UNRESOLVED | The directory is not in a Git repository with a commit, or --revision is not a local branch, tag or commit | Run git init and commit, fetch or create the revision, or pass the full commit |
RECIPE_PACKAGE_SCHEMA_RETIRED | recipe.toml uses the retired envloop.recipe-publication/v3 format | Rewrite it as envloop.recipe/v3 and add entrypoint.sh |
RECIPE_SCHEMA_UNSUPPORTED | Missing or other schema_version | Set schema_version = "envloop.recipe/v3" |
RECIPE_ABI_UNSUPPORTED | [runner] abi is not envloop.recipe/1 | Set abi = "envloop.recipe/1" |
RECIPE_DECLARATION_INVALID | Unknown table or key, or a source.repository that is not https://github.com/OWNER/REPO | Keep to the tables above; omit repository or use a GitHub repository URL |
RECIPE_PARAMS_INVALID | Invalid param declaration or a reserved name | Fix the declaration; rename params that use a standard name |
RECIPE_PATH_NOT_FOUND | A paths entry matches nothing, or exclude names an unselected file | Correct the paths |
RECIPE_DECLARATION_CONFLICT | paths would put another file at the package root recipe.toml or entrypoint.sh | Narrow paths or exclude that file |
RECIPE_FILE_UNSUPPORTED | A selected path is a symlink or submodule | Remove it from paths or exclude it |
RECIPE_PACKAGE_TOO_LARGE | More than 1000 files, 512 MiB per file or 1 GiB in total | Narrow paths |
RECIPE_NAME_MISMATCH | The upload's URI name differs from [recipe] name | Publish with --directory so the URI comes from recipe.toml |
RECIPE_INDEX_INVALID | Uploaded files do not match their content index | Publish with --directory instead of a hand-written manifest |
RECIPE_READBACK_MISMATCH | The catalog did not return the published Recipe as ready | Check it with el recipe get URI before retrying |
RECIPE_ABI_MISMATCH | The Runner Revision does not implement envloop.recipe/1 | Pin a Runner Revision that does |
RECIPE_TYPE_UNSUPPORTED | The Job type is not in both the Runner's and the Recipe's types | Submit a supported type, or add it to [recipe] types |
RECIPE_PARAM_REQUIRED | A required Recipe param has no value in any layer | Set it in params |