Skip to main content

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​

RunnerRecipe
Maintained byThe platformYou
Declarationrunner.tomlrecipe.toml
Entry filemain.shentrypoint.sh
DecidesImage, resources, network and the standard params image, command, timeout_seconds, max_retriesJob types, params, input slots and your code
IdentityNAMESPACE/NAME@FULL_COMMITenvloop://recipes/NAMESPACE/NAME@<recipe-sha256>

Every Recipe runs through the same call chain:

  1. The platform starts the Runner's main.sh and prepares the handoff files below.
  2. main.sh runs bash "$ENVLOOP_RECIPE_ROOT/entrypoint.sh". The executable bit is not needed.
  3. Your entrypoint.sh runs your code.
VariableContent
ENVLOOP_RECIPE_ROOTRead-only directory holding the unpacked Recipe package
ENVLOOP_JOB_FILEJSON: job_id, trial_id, type and the resolved resources
ENVLOOP_PARAMS_FILEJSON: the merged and validated Recipe params
ENVLOOP_INPUTS_FILEJSON: each input slot's local path, uri and manifest_sha256
ENVLOOP_OUTPUT_DIRWritable 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
  1. Package contents. The package root holds recipe.toml and entrypoint.sh. The files selected by [source].paths keep their paths relative to the repository root. For the monorepo above, write paths = ["training/hello"] and run training/hello/train.py from $ENVLOOP_RECIPE_ROOT/training/hello/train.py.
  2. Selection. paths lists files or directories. exclude lists exact files already selected. Ignored and unselected files are never packaged.
  3. 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 ..
  4. 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 init and commit once; no remote is needed.

Python dependencies​

The package holds only your files. Your code can use packages in two ways.

  1. Packages in the Runner image. envloop/train runs in a public PyTorch CUDA runtime image with Python, PyTorch and pip. The dry run shows the exact image in params.image. To use another public image that already has your packages, set params.image.
  2. Install them in entrypoint.sh. Commit a requirements file with pinned versions under [source].paths and install it before starting your code:
python3 -m pip install --user --no-cache-dir -r "$ENVLOOP_RECIPE_ROOT/src/requirements.txt"
  1. Network. Installing needs outbound access, which the Runner decides; envloop/train allows it ([sandbox] allow_internet = true). On a Runner without network access the install fails.
  2. Where packages go. --user installs 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 $HOME instead.
  3. Time. Installation counts toward the Trial's params.timeout_seconds.
  4. 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.

recipe.toml
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
  1. [recipe]. name is the NAMESPACE/NAME of the Recipe URI. types lists the Job types it supports: bench, sandbox, train or inference.
  2. [runner]. The Runner it targets and the Recipe ABI. abi is always envloop.recipe/1.
  3. [source]. paths selects the packaged code. repository is optional: omit it for a local-only repository, as here, or set repository = "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.
  4. [inputs.SLOT]. kind is dataset, checkpoint or artifact. train_dataset and eval_dataset are Datasets; checkpoint and resume_from_checkpoint are Checkpoints.
  5. [params]. Each param has type, and optionally default, required, description, enum, minimum, maximum and locked. A required = true param has no default and must be set for every Job. A locked param keeps its default. An object param lists its fields under properties and accepts no other fields unless additional_properties = true.
  6. Reserved names. The standard params image, command, timeout_seconds and max_retries belong 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, an enum subset, and the Runner's locks and required params kept. Otherwise the result is RECIPE_PARAM_CONFLICT. envloop/train declares only standard params.
  7. Optional tables. [outputs] files lists other files the Recipe writes under $ENVLOOP_OUTPUT_DIR. [dependencies.SLOT] pins another published Recipe by uri and manifest_sha256.
entrypoint.sh
#!/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
src/hello/train.py
"""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"}
}
  1. 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 list train in its types. Find one with el runner list --json.
  2. recipe. NAMESPACE/NAME@<recipe-sha256>, where the digest is the receipt's manifest_sha256. Only a digest is accepted.
  3. 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, so optimizer.warmup_steps keeps its Recipe default here. The standard params image, command, timeout_seconds and max_retries are set here too. The Trial reads the merged non-standard params from ENVLOOP_PARAMS_FILE.
  4. 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 in ENVLOOP_INPUTS_FILE.
  5. 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​

CodeCauseFix
RECIPE_DECLARATION_NOT_FOUNDNo recipe.toml in --directory at that revisionCommit it, or point --directory at the directory that holds it
RECIPE_ENTRYPOINT_NOT_FOUNDNo entrypoint.sh next to recipe.tomlCommit entrypoint.sh in the same directory
RECIPE_PACKAGE_UNCOMMITTEDPackaged paths differ from the branch or tagCommit or remove the changes, or pass a full commit
RECIPE_REVISION_UNRESOLVEDThe directory is not in a Git repository with a commit, or --revision is not a local branch, tag or commitRun git init and commit, fetch or create the revision, or pass the full commit
RECIPE_PACKAGE_SCHEMA_RETIREDrecipe.toml uses the retired envloop.recipe-publication/v3 formatRewrite it as envloop.recipe/v3 and add entrypoint.sh
RECIPE_SCHEMA_UNSUPPORTEDMissing or other schema_versionSet schema_version = "envloop.recipe/v3"
RECIPE_ABI_UNSUPPORTED[runner] abi is not envloop.recipe/1Set abi = "envloop.recipe/1"
RECIPE_DECLARATION_INVALIDUnknown table or key, or a source.repository that is not https://github.com/OWNER/REPOKeep to the tables above; omit repository or use a GitHub repository URL
RECIPE_PARAMS_INVALIDInvalid param declaration or a reserved nameFix the declaration; rename params that use a standard name
RECIPE_PATH_NOT_FOUNDA paths entry matches nothing, or exclude names an unselected fileCorrect the paths
RECIPE_DECLARATION_CONFLICTpaths would put another file at the package root recipe.toml or entrypoint.shNarrow paths or exclude that file
RECIPE_FILE_UNSUPPORTEDA selected path is a symlink or submoduleRemove it from paths or exclude it
RECIPE_PACKAGE_TOO_LARGEMore than 1000 files, 512 MiB per file or 1 GiB in totalNarrow paths
RECIPE_NAME_MISMATCHThe upload's URI name differs from [recipe] namePublish with --directory so the URI comes from recipe.toml
RECIPE_INDEX_INVALIDUploaded files do not match their content indexPublish with --directory instead of a hand-written manifest
RECIPE_READBACK_MISMATCHThe catalog did not return the published Recipe as readyCheck it with el recipe get URI before retrying
RECIPE_ABI_MISMATCHThe Runner Revision does not implement envloop.recipe/1Pin a Runner Revision that does
RECIPE_TYPE_UNSUPPORTEDThe Job type is not in both the Runner's and the Recipe's typesSubmit a supported type, or add it to [recipe] types
RECIPE_PARAM_REQUIREDA required Recipe param has no value in any layerSet it in params