---
sidebar_label: "Recipe repository"
title: "Write a Recipe in your own repository"
description: "Keep recipe.toml, entrypoint.sh and your code in a local or GitHub Git repository, publish them with el recipe create and run them in a Train Job."
last_update:
  date: 2026-11-18
---

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-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:

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.

| 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 {#repository-layout}

`recipe.toml` and `entrypoint.sh` sit next to each other. They can be at the repository root:

```text
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:

```text
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 {#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](#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:

```bash
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 {#example}

This example trains a stand-in model on one Dataset input. It uses only the Python standard library.

```toml title="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`.

```bash title="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
```

```python title="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 {#publish}

Commit the files, preview the Recipe, then publish it:

```bash
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](recipes.md#visibility).

## Run it in a Train Job {#run}

Save the Job spec as `job.json`, replacing the placeholders with a full Runner commit, the published Recipe digest and your own Dataset:

```json
{
  "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`.

```bash
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:

```json
{
  "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`:

```bash
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 {#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` |
