Core Guides

Run Reef in production

The deployment file that runs on one host also runs in production. For production you choose where each part runs: the processes, the state, the training, the serving, the task sandboxes, and the agents that connect.

What you choose for production. Agents, apps and coding agents call Reef. Reef's seven services run in one process or one process each. Serving runs on SGLang or vLLM on your GPUs, on an upstream provider or on Tinker's sampler. Training runs on Slime on your GPUs, on Tinker, on Spindle on Modal or on your own backend. Task sandboxes run on Docker, E2B or Modal. Every service reads and writes the state: records and work queues in SQLite or PostgreSQL, versions in a Git LFS repository, and files on a disk that the hosts share. What you choose for production. Agents, apps and coding agents call Reef. Reef's seven services run in one process or one process each. Serving runs on SGLang or vLLM on your GPUs, on an upstream provider or on Tinker's sampler. Training runs on Slime on your GPUs, on Tinker, on Spindle on Modal or on your own backend. Task sandboxes run on Docker, E2B or Modal. Every service reads and writes the state: records and work queues in SQLite or PostgreSQL, versions in a Git LFS repository, and files on a disk that the hosts share.

Each choice is one section of this page:

You choose

Options

Set with

The processes

One process, or one process for each service

reef serve --service NAME

The state

SQLite on one host, or PostgreSQL; a Git LFS repository, local or on Hugging Face

storage

The training

Slime on your GPUs, Tinker, Spindle on Modal, or your own backend

training.backend

The serving

SGLang or vLLM on your GPUs, a remote GPU host, Tinker's sampler, or an upstream provider

inference

The task sandboxes

Docker, E2B or Modal

environment of an evaluation, evolution.executor

The agents

Any OpenAI-compatible client, reef-client, or a coding agent

The client's base URL

Access and monitoring

Tokens, a proxy for TLS, logs, Weights & Biases, OpenTelemetry

reef.tokens, observability

On AWS and Google Cloud says which cloud service fills each part. Production interfaces gives the contract of each part: what is built in, what the tests cover, and the base class of a class of your own.

Before you start #

Run the loop once on one host: Use Reef. Choose the state before the first training job: a change of backend later does not move the data.

From one host to production #

Start from the deployment file that runs on one host, such as the one of the minimal recipe (serve.yaml) from Use Reef. The recipe, inference and training sections stay as they are. Three things change:

YAML
reef:
  # Listen for other hosts. Reef refuses a public address without a token.
  host: 0.0.0.0
  tokens:
    - ${REEF_TOKEN}
storage:
  # The records and the work queues, for every service.
  record-backend: postgres
  record-database-url: ${REEF_RECORD_DATABASE_URL}
  # The versions and the files, on a disk that every host mounts.
  artifact-repository: /mnt/reef/artifacts.git
  agent-record-dir: /mnt/reef/agent-record
activation:
  # Hold each new version back until you choose it.
  module: never

Then start one process for each service, with the same file:

Shell
reef serve -c deploy.yaml --service control --reef.port 8900
reef serve -c deploy.yaml --service inference --reef.port 8902
reef serve -c deploy.yaml --service samples --reef.port 8903
reef serve -c deploy.yaml --service training --reef.port 8904

Check each process with curl -f http://<host>:<port>/healthz. Model calls go to the inference process, and scenarios and reports go to control (Route the requests). The sections below give each choice in full.

What we ran: the loop of Use Reef on one host with two GPUs, SQLite and a local repository. The settings of this section are checked by a test to be settings of Reef; a deployment on several hosts was not run for this page.

Split the services #

reef serve runs the seven services in one process. To scale a service, or to keep inference up while control restarts, run one process for each service:

Shell
reef serve -c deploy.yaml --service control --reef.port 8900
reef serve -c deploy.yaml --service inference --reef.port 8902

Every process needs the same Reef version, the same deployment file, the same REEF_TOKEN, and the shared state of the next section. Each process has its own port, storage.artifact-work-dir and storage.artifact-cache-dir.

Service

How many

Needs

control

One active, and standbys that take over

The state

inference

Any number; one of them starts the engines

The GPUs, or the address of the engines

samples

Any number

The state

training

training.max-jobs jobs for each process

The training backend's credentials, and write access to the checkpoints

evaluation

evaluation.max-sandboxes sandboxes for each process

The sandbox provider's credentials

data, harness

Any number

The state

The control, samples, training and inference processes also need the recipe's package. To check it, curl -f the /healthz of each process, and read GET /reef/status on control. The two parts below say where each request goes, and what a restart of each service does.

Route the requests #

Send each request to the service that lists its route (Services). Only inference answers model requests:

  • Set harness.inference-url to an inference address that harness clients reach.

  • For a composite recipe, set reef.served-url to an inference address that the other services reach.

reef-client harness connect also lists and creates scenarios, so point it at control. Other harness clients can call the harness service. Keep engine addresses private. After 30 seconds without control, a data write returns synced: false and a harness import returns 503; both stay queued, and sending the same files again waits for the first import.

Restart a service #

  • Control: inference and queued work continue; new work and data sync wait. A standby takes over. Send control traffic to the instance that answers /healthz. To upgrade, start the new standby before you stop the active one.

  • Inference: when another replica takes over the engines, it starts them again, local and remote, and requests in flight end. Poll startup status before you send traffic. Restart inference after a reset of the coordination store.

  • Training: jobs wait and consume no samples. Tinker and Spindle imports return 503 after 60 seconds.

  • Evaluation: with evaluation.on-stop: finish, set evaluation.finish-timeout-s below the supervisor's kill deadline. A forced kill uses up an attempt, and the retry waits for the lease to expire.

To check a restart, read GET /reef/status on control.

Keep the state #

On one host the defaults work: SQLite and a local Git repository under .reef/. Several hosts share three things.

Records and work queues: PostgreSQL. Any PostgreSQL that the hosts reach works. The role must create schemas:

Shell
uv pip install 'reef-infra[postgres]'
YAML
storage:
  record-backend: postgres
  record-database-url: ${REEF_RECORD_DATABASE_URL}

To check it, start Reef: it creates the schemas reef_records, reef_records_coordination and reef_data.

Versions: a Git LFS repository. The default is a local repository. Hosts can share it on a disk where file locks work, such as NFS. Or keep the versions in a Hugging Face repository:

YAML
storage:
  artifact-backend:
    module: reef.artifact.git_lfs:GitLFSRepositoryBackendFactory
    config:
      repository: https://huggingface.co/org/my-versions
      refs: branches-and-tags
      token_env: HF_TOKEN

Files: a shared disk. Every service must reach the task files and the job directories under storage.agent-record-dir, and the training host must reach the checkpoints. For another kind of storage, such as an object store, write a plugin: storage.artifact-backend, storage.segment-backend and storage.task-file-backend each take a package.module:ClassName.

The parts below cover the data store, the retention of records, the backup and the upgrade.

Isolate the data store #

The data store holds the data items (records, trajectories, tasks, artifacts). Deployments with different record schemas still share reef_data. To isolate one:

YAML
storage:
  data-store:
    module: reef.storage.sql.data:PostgresDataStore
    config:
      database_url: ${REEF_DATA_DATABASE_URL}
      schema: reef_data_acme

Every service must also reach the task files and either the segment files or <agent-record-dir>/job-directories; across hosts, use shared-store plugins. Once content is in segments, keep storage.segment-backend set, or Reef cannot read it. To check it, read an uploaded item through a service on another host.

Record retention #

storage.agent-record-retention-max-bytes caps record bodies, not disk use: indexes and delayed cleanup take more, and SQLite does not shrink its file. Reef skips a pending report whose records were removed and logs a warning; keep backups for longer retention. To check it, the pipeline object of /reef/status counts evicted records.

Back up a deployment #

With all writers stopped, copy:

  • the scenario, data and coordination databases, custom schemas included;

  • the artifact repository with its Git LFS objects, or the plugin's storage;

  • the task files, segment files and job directories;

  • the training checkpoints, the backend state-dir and the harness evolution.state_dir.

Working copies and caches can be rebuilt. Tinker artifacts also need their remote checkpoints and service.

Upgrade from a Reef that wrote older formats #

Back up first. The data store upgrades in one transaction, and older Reef versions then refuse it. A data store or PostgreSQL record schema newer than this version fails without changes. This version reads only reef-commit/9 and reef-scenario/8 commits and scenario metadata, with no migration: for older formats, use a new deployment directory or schema and create the scenarios again. Reef leaves the old data. To check it, read /reef/status.

Train #

training.backend selects where the jobs train. The recipe stays the same.

Backend

Trains

Install

Credentials

slime (default)

All parameters or LoRA, on your GPUs

The Reef GPU image

None

tinker

LoRA, on the Tinker service; the Reef host needs no GPU

reef-infra[tinker]

TINKER_API_KEY

spindle_full

All parameters, on a Spindle engine that you deploy on Modal

reef-infra[tinker] and reef-infra[modal]

The Spindle key in TINKER_API_KEY, MODAL_TOKEN_ID, MODAL_TOKEN_SECRET, HF_TOKEN

Slime on your GPUs. Slime trains on a Ray cluster: the one that Reef starts on this host, or yours at training.ray-address. The training GPUs and the serving GPUs are separate:

YAML
inference:
  num-gpus: 4
training:
  backend: slime
  options:
    actor-num-gpus-per-node: 4
    num-gpus-per-node: 8
    global-batch-size: 32

Slime trains one scenario for each deployment, and every weight recipe that ships trains on it. Train model weights has the GPU image and the checkpoint settings.

Tinker. Give the key and a directory that the deployment keeps:

YAML
training:
  backend: tinker
  options:
    state-dir: /var/lib/reef/tinker
    lora-rank: 32

Tinker's sampler serves the model: text chat only, with no tool calls. Tinker trains the sft algorithm and TTT-Discover. Train with Tinker has the limits, and the Spindle deployment.

Your own backend. training.backend also takes the package.module:ClassName of a TrainingDeployment (Training backends).

Train with Tinker #

Tinker trains a LoRA adapter on its own service, so the Reef host needs no GPU. You need a Tinker API key in TINKER_API_KEY and the extra reef-infra[tinker].

Run the smoke test.

Shell
uv pip install -e '.[tinker]'
export TINKER_API_KEY="..."
export REEF_TOKEN=reef-local
export REEF_TINKER_STATE_DIR="$PWD/work/tinker-smoke"
reef serve -c tutorials/tinker/serve.yaml
# when /healthz answers, in another terminal with the same environment:
python tutorials/tinker/smoke.py

The paid test trains one step on synthetic rewards; run it once per new state directory. It prints Committed one Tinker update on success. See the example.

Configure a deployment.

Set training.backend: tinker, a Tinker model, and a persistent training.options.state-dir for this deployment alone (training settings). Tinker then serves one training scenario; to serve more, serve on SGLang (below).

  • The Tinker sampler takes text messages on /v1/chat/completions only. Tools, multimodal content, other routes, several outputs and unknown options return 400.

  • A stream arrives as one SSE reply when the answer is complete.

  • With no token limit, the answer can fill the context window (1024 tokens when the service states none). A prompt that fills the window returns 400 context_length_exceeded.

  • Use one chat template for training and serving: a sample that does not render or fit does not train.

  • Tinker trains sft and TTT-Discover. SAO, SDFT, SDPO, OPD and OpenClaw-RL need Slime.

To check it, GET /reef/scenarios/{scenario}/artifacts lists a new artifact after a job.

Jobs, checkpoints and recovery.

A new scenario serves the base model. A job restores weights and optimizer state, saves at its end, and saves every recipe.config.job_parameters.save_interval optimizer steps when set. The next job, and a restart, continue from the last save, served or not (train-from changes this).

An artifact references a remote checkpoint: keep the account, project, service and checkpoints. Reef never deletes them and rejects checkpoints of another service. An API call with an unknown result can cost credits or leave a checkpoint that no artifact names.

Serve on SGLang.

YAML
inference:
  model-path: Qwen/Qwen3-8B
  backend: sglang
  num-gpus: 2
  max-loaded-adapters: 2
training:
  backend: tinker
  options:
    state-dir: /var/lib/reef/tinker
    lora-rank: 32

Reef converts each checkpoint to a PEFT adapter. Give one adapter slot per scenario, plus one for an update. Match the base model, tokenizer and chat template; SGLang must support lm_head adapters. Spindle checkpoints cannot serve this way, and only stub-engine tests cover this setup. To check it, poll inference/status until state is ready.

Serve from a remote GPU host.

On a GPU host with Reef and SGLang, run python -m reef.inference.remote --port 8000 with REEF_REMOTE_CONTROL_TOKEN and REEF_REMOTE_INFERENCE_TOKEN set to two different values. Set the same variables on the Reef host, and inference.remote.url (prefer HTTPS). The control token can start model code and replace weights. One runtime controls the component, and stopping it stops the engines. Reef checks the component every 30 seconds and reloads adapters after a restart.

Train all parameters on Spindle.

Deploy a Spindle full-parameter engine for the exact base revision, install reef-infra[modal], and supply Modal credentials, the Spindle key in TINKER_API_KEY and an HF_TOKEN that reads the base:

YAML
inference:
  model-path: org/model
training:
  backend: spindle_full
  options:
    state-dir: /var/lib/reef/spindle-full
    base-url: https://<workspace>--spindle-server.modal.run
    base: hf://org/model@0123456789abcdef0123456789abcdef01234567
    release-repo: org/model-releases
    modal-environment: spindle
    learning-rate: 1.0e-6

Each checkpoint exports weights, tokenizer and templates to a new release commit. Spindle serves it by default, and Reef's engines can load it. An import must match the base or hold a full-parameter manifest of the same service; other weights return 400. Use one engine and scenario per base. Each job pays for GPU startup and export. The training settings describe each key, score-centering included.

Serve #

The model serves on

Set

Note

SGLang or vLLM on this host's GPUs

inference.backend: sglang or vllm, inference.num-gpus

The default is SGLang. vLLM serves full weights only.

A GPU host that you run

inference.remote.url

The host runs python -m reef.inference.remote. Two tokens protect it.

Tinker's sampler

training.backend: tinker

The default with Tinker. inference.backend: sglang serves the adapters on your GPUs instead; Reef's tests cover that only with a stub engine.

An upstream provider

inference.upstream-url, inference.upstream-model

For a recipe that trains no weights: Reef records the calls, or evolves a harness.

Your own runtime

inference.serving: package.module:Factory

Serving runtimes

A new version loads into the running engine. Poll GET /reef/scenarios/{scenario}/inference/status until state is ready before you send traffic after a restart. Inference settings has the keys of each row.

Run tasks in sandboxes #

Reef runs a task in a sandbox in two places: an evaluation of a version, and the evaluation runs of a harness recipe.

Provider

Install

Credentials

Note

Docker

A running Docker daemon

None

The default of an evaluation

E2B

reef-infra[e2b]

E2B_API_KEY

Starts the task's own image. A task with several Compose services needs an AgentENV deployment.

Modal

reef-infra[modal]

MODAL_TOKEN_ID, MODAL_TOKEN_SECRET

A sandbox lives 24 hours at most

An evaluation names its provider in the request:

Shell
curl -fsS -H "Authorization: Bearer $REEF_TOKEN" -H 'Content-Type: application/json' \
  "$REEF_URL/reef/scenarios/demo/evaluations" \
  -d '{"artifact_id": "<artifact_id>", "harness": {"name": "terminus-2"}, "environment": "e2b"}'

The evaluation service runs evaluation.max-sandboxes sandboxes at once (4 by default). Set it to the provider's quota divided by the number of evaluation processes. With the activation rule evaluated, a version serves when its evaluation reaches min_mean_score (Evaluation).

A harness recipe names its provider in the deployment file: recipe.config.evolution.executor takes local, sandbox, e2b or modal. E2B and Modal refuse egress_hosts and limits (Harness settings).

For another provider, write a RemoteExecutor (Sandboxes).

Connect an agent #

An agent uses Reef as its model endpoint: any OpenAI-compatible client, the Python reef-client, or a coding agent such as Claude Code, Codex, OpenCode or pi. Connect an agent gives each way, the adapters, and how to write an adapter.

Secure and observe #

  • Tokens. Set reef.tokens. Every token opens every route, and several tokens let you change one without downtime. Reef refuses to listen on a public address without a token. Put a gateway in front of Reef for per-user permissions.

  • TLS. Reef serves HTTP. Put a proxy that ends TLS in front of it.

  • Browser consoles. reef.console-origins lists the origins that may call Reef.

  • Status and logs. GET /reef/status on control gives each scenario's state. Each process writes <reef.run-dir>/<process>.log.

  • Metrics and traces. observability.wandb sends metrics to Weights & Biases (reef-infra[wandb]). observability.tracing sends the records as OpenTelemetry traces, message content included (reef-infra[opentelemetry]). See Observability.

On AWS and Google Cloud #

Reef uses standard parts, so it runs on either cloud. The table says which service fills each part. Reef's own code for a cloud is the S3 reader and writer only.

Reef needs

On AWS

On Google Cloud

In Reef

Hosts with GPUs, for Slime and the engines

EC2 GPU instances

Compute Engine GPU instances

The Reef GPU image runs on any host with NVIDIA GPUs

PostgreSQL

RDS for PostgreSQL

Cloud SQL for PostgreSQL

storage.record-database-url

A disk that the hosts share

EFS

Filestore

An NFS mount. A FUSE mount of an object store does not work for the Git repository.

A place for the versions

The shared disk, or Hugging Face

The shared disk, or Hugging Face

storage.artifact-backend. An S3 or GCS backend is a plugin that you write.

Imports and exports of data

s3:// URIs, with reef-infra[s3]

Not built in

Data upload

Task sandboxes

Docker on the hosts, or E2B or Modal

Docker on the hosts, or E2B or Modal

Run tasks in sandboxes

Reef ships no Kubernetes chart. Each service is one reef serve --service NAME process with /healthz, so a process manager or an orchestrator of your choice runs them.

Before you go live #

  1. The state is on PostgreSQL and a repository that every host reaches.

  2. reef.tokens is set, and a proxy ends TLS.

  3. Each process answers /healthz, and GET /reef/status shows no error.

  4. A test scenario went through the whole loop: Use Reef, steps 2 to 5.

  5. You stopped the writers and copied the state once (backup).

Next steps #