This recipe condenses The ultimate guide to multi-harness RL. All code lives in the pinned companion tutorial and TRL’s Harbor example. New to harness training? Start with Training a coding agent using the OpenCode harness in remote HF sandboxes with TRL and OpenEnv, a single-harness walkthrough of the same stack. Besides the two GPUs (one trainer, one vLLM server), each rollout needs a remote sandbox: E2B in the reported runs, Daytona in the current tutorial.
1. How the pieces fit
A harness finds the model the way it would find any provider, through a base URL and an API key. The proxy hands each rollout a session id as its API key, forwards calls to vLLM, and records prompt token ids, sampled token ids and per-token logprobs. The harness never talks to vLLM or to the trainer directly.
Harbor
Runs the chosen harness against a containerised task, then runs the task’s verifier. SmolDataEnvs tasks are Kaggle-notebook questions with deterministic graders.
OpenEnv
Serves Harbor tasks as an environment and runs the capture proxy. Each root-to-leaf path in the call graph becomes one training sequence with a loss mask.
TRL
HarnessRolloutWorker requests rollouts through HarborSessionFactory and feeds each TrainingTrace to AsyncGRPOTrainer.
reward=None and is excluded, not scored as wrong.For the full design (API dialect detection, rollout graphs, ATIF cross-checks, per-harness wiring) see the Harbor page of the OpenEnv docs and the original article.
2. Install and prepare the tasks
Use Python 3.12: on 3.10 or 3.11, openenv[harbor] skips the Harbor dependencies. The tutorial’s installer pulls TRL, OpenEnv and Transformers from main (the harness worker is not in a TRL release yet), and prepare.py downloads the pinned 1,000 training and 250 test tasks and checks their graders and split separation.
git clone https://github.com/adithya-s-k/FineEnvs.git
cd FineEnvs && git checkout 6f2b6137b8253377ca97f898742974ba724f4046
cd 05-multi-harness-rl
uv venv --python 3.12 --seed .venv
source .venv/bin/activate
bash jobs/install.sh
hf auth login
export HF_TOKEN="$(hf auth token)"
export DAYTONA_API_KEY="your-key"
python prepare.py
3. Check the environment before training
Rollouts are only trainable if the engine returns token ids and per-token logprobs. Serve with full-vocabulary sampling (top_p=1, no top_k) and these vLLM flags; the proxy probes the engine and marks anything weaker as evaluation-only.
vllm serve LiquidAI/LFM2.5-2.6B --return-tokens-as-token-ids --logprobs-mode processed_logprobs
Then use the openenv harbor CLI to confirm each harness produces a clean capture before involving the trainer:
| Command | Use it to |
|---|---|
openenv harbor info | See whether the engine returns token ids, which sandbox backends have credentials, and which datasets and harnesses resolve. Starts nothing. |
openenv harbor rollout | Run rollouts without a server. If one works here but fails under serve, the fault is in the serving layer. |
openenv harbor serve | Start the environment server (Task API, MCP run_rollout tool, web UI and capture proxy). |
openenv harbor push | Deploy the same server to a Hugging Face Space. |
openenv harbor info --llm-url $LLM --dataset FineEnvs/SmolDataEnvs-harbor-train
openenv harbor rollout --llm-url $LLM --dataset FineEnvs/SmolDataEnvs-harbor-train \
--task-index 0 -n 5 --harness opencode --sandbox daytona
A healthy rollout prints ok, a reward and atif=match, meaning the captured turns agree token-for-token with Harbor’s own trajectory file. Repeat with --harness claude-code, codex and mini-swe-agent. To try it in a browser first, open the SmolDataEnvs Harbor Space.
4. Wire the trainer
Pick the script that matches who runs the tool loop. All three share tasks, reward and evaluation, and each reads top to bottom: settings → tokenizer → environment → reward → TRL config → training.
| Script | Tool loop | Trainer |
|---|---|---|
train/multi_harness.py | Harbor runs OpenCode, Claude Code, Codex or Mini-SWE-Agent | AsyncGRPOTrainer |
train/opencode.py | Native OpenCode in a sandbox (single-harness baseline) | AsyncGRPOTrainer |
train/whitebox.py | TRL calls Python bash tools itself | GRPOTrainer |
The key choices in the multi-harness script:
- One harness per GRPO group.
TaskFactoryassigns each task one harness in rotation and all eight rollouts use it, so the advantage compares actions, not harnesses. - Reward = correctness × (1 + tool bonus). The bonus is
0.1 · 15 / (15 + tool_calls), so a correct answer earns 1.0–1.1 and a wrong one earns 0. It gives all-correct groups a contrast (22.6% of multi-harness groups relied on it) and stops tool use from creeping up. Never sum several verifier scores into one reward; pick one by name. harness_adapter=Nonelets the harness own its loop; OpenEnv captures its model calls.- Raise
max_concurrent_envson the server: the default of 4 is below one GRPO group of 8, and excess rollouts are rejected withCAPACITY_REACHED.
Shared settings from the tutorial (see each script’s TRL config for the rest):
| Setting | Value |
|---|---|
| Model | LFM2.5-2.6B or Qwen3.5-2B, non-thinking |
| Tasks | 1,000 train (400 medium, 600 hard) · 250 test, no notebook or question overlap |
| Learning rate | 3e-6, constant, no warmup |
| Rollouts per group | 8 |
| Async limits | 32 in flight, max staleness 4 |
| Batching | Batch 4, accumulation 4, packed row budget 40,960 tokens |
| Output cap | 4,096 tokens per model call, in both training and evaluation |
| Agent turns | Up to 17 model calls per rollout (Harbor) |
| Steps | Up to 1,000 optimizer updates, checkpoint every 50 |
5. Run: smoke, pilot, full
Start with a two-step smoke that trains, saves, reloads checkpoint 2 into vLLM and evaluates it. A passing smoke proves execution, not learning. The launcher (jobs/run.py) starts vLLM and the environment servers inside the job, so nothing has to be running beforehand. The command builder above writes these commands for any mode, model and step count.
HF Jobs
jobs/hf_job.py needs only huggingface_hub on your laptop. It prints the plan; add --submit to launch on h200x2. Checkpoints go to a mounted bucket at /outputs.
export RUN_BUCKET="your-org/smoldataenv-runs"
python jobs/hf_job.py smoke --mode multi_harness --name lfm-harbor-smoke \
--bucket "$RUN_BUCKET" --timeout 1h --submit
# Baseline, 100-step pilot, then evaluate checkpoint 100 on the same 25 tasks
python jobs/hf_job.py eval --mode multi_harness --tasks 25 --name lfm-baseline --bucket "$RUN_BUCKET" --submit
python jobs/hf_job.py train --mode multi_harness --steps 100 --name lfm-harbor-100 --bucket "$RUN_BUCKET" --submit
python jobs/hf_job.py eval --mode multi_harness --tasks 25 \
--checkpoint /outputs/lfm-harbor-100/checkpoint-100 --step 100 \
--name lfm-harbor-100-eval --bucket "$RUN_BUCKET" --submit
A local two-GPU machine
The same smoke runs directly on a machine with two GPUs:
CUDA_VISIBLE_DEVICES=0,1 python jobs/smoke.py --mode multi_harness --output runs/harbor-smoke
Use --mode opencode for the single-harness comparison and --model Qwen/Qwen3.5-2B for Qwen. Omit --steps and --tasks for the full 1,000-step run and 250-task evaluation.
6. Evaluate
eval/evaluate.py runs each test task once under each of the four harnesses (1,000 cells for 250 tasks) and counts a cell as solved when its first graded attempt is correct. Read summary.json for pass@1, tool calls and tokens by harness and difficulty.
- Report coverage with pass@1.
pass_at_1_observedexcludes ungraded pairs. A partial evaluation exits with status 2; rerun the same command and output directory to retry only the missing pairs. - Trust trends, not single checkpoints. Each cell runs once, so a point or two between neighbouring checkpoints is noise.
See the evaluation guide for deployed endpoints and checkpoint loading.
Results
Two runs of LFM2.5-2.6B for 1,000 steps on two H100s each: one trained in OpenCode only (about 32 h), one rotating all four harnesses across GRPO groups (about 46 h). Both evaluated under all four harnesses.
Bars are in the order base, OpenCode-only RL, multi-harness RL. 250 held-out tasks per harness, one attempt each. The 1.9-point overall gap between the two RL runs is within noise; the per-harness split is the clear signal. All curves and checkpoints
- A model improves where it trains. OpenCode-only RL gained 24 points in OpenCode but little elsewhere. Multi-harness RL improved under all four.
- Fewer tool calls. On tasks both the base and trained model solved, multi-harness RL used 31% fewer calls (about half under Codex); OpenCode-only RL used 11% fewer and more than the base model under Claude Code.
- Steps are not equal exposure. Claude Code rewrites its history, so each of its rollouts became about eight training rows. The multi-harness run processed 451M training tokens against 162M for OpenCode-only.
RL vs SFT on a teacher’s rollouts
The same capture also records whole trajectories, so a larger model’s successful rollouts can be used for SFT. Qwen3.8-27B solved 888 training tasks across the four harnesses (3,189 rollouts), and LFM2.5-2.6B was fully fine-tuned on them with SFTTrainer for two epochs (LR 3e-6, effective batch 8). Data and a training script are in SmolDataEnvs-multiharness-sft.
| Model | Overall | OpenCode | Claude Code | Codex | Mini-SWE | Train time |
|---|---|---|---|---|---|---|
| Base | 42.2 | 33.6 | 33.2 | 40.0 | 62.1 | – |
| SFT · OpenCode | 47.5 | 51.6 | 33.2 | 46.4 | 58.8 | 1.5 h |
| SFT · multi-harness | 43.1 | 38.0 | 42.4 | 46.8 | 45.2 | 6.5 h |
| RL · OpenCode (step 900) | 52.4 | 56.0 | 43.6 | 48.4 | 61.6 | 32 h |
| RL · multi-harness (step 700) | 54.6 | 51.2 | 48.8 | 53.6 | 64.8 | 46 h |
RL rows use each run’s best checkpoint on the test set, which flatters RL slightly (both are within half a point of step 1,000). RL ends ahead of both SFT runs. Multi-harness SFT gained 4–9 points in three harnesses but lost 17 under Mini-SWE-Agent. SFT times exclude collecting the teacher’s rollouts. Each setup ran once, so treat this as an observation rather than a ranking of methods.
Pitfalls the runs surfaced
- Mismatched output caps. An earlier Qwen3.5-2B run trained with a 16,384-token cap but evaluated at 4,096. Answers grew until 556 of 1,000 eval cells were cut off, and pass@1 fell from 37% back to 26%. Use the same cap in both.
- Correctness-only reward. With no efficiency term, tool calls per rollout doubled in one run, and 35–58% of optimizer steps had no reward contrast in any group.
- Shaping terms leak into the objective. A
+0.2for submitting anything taught the policy to submit immediately; held-out accuracy fell from 0.740 to 0.178 while training reward looked healthy. - Truncated sampling.
top_pbelow 1 biases sampling away from the policy and makes vLLM logprobs disagree with it. Moving totop_p=1.0took the importance ratio from 0.985–0.993 to 0.9984–0.9999. - Proxy capacity. One capture proxy process started to starve around 200 concurrent sessions and crashed at 320.
Artifacts
- Trained models: LFM multi-harness RL and OpenCode-only RL (best checkpoints on the
step-700andstep-900branches), multi-harness SFT, OpenCode SFT. - Data: SmolDataEnvs Harbor training set (browse it in the Harbor visualiser), raw teacher rollouts.
- Environments: Harbor environment Space and its source.
- Integrations: OpenEnv #1036 (capture proxy and Harbor), OpenEnv #1280 (
TrainingTrace), TRL #6947 (HarnessRolloutWorker). - Further reading: Training a coding agent using the OpenCode harness in remote HF sandboxes with TRL and OpenEnv (single-harness walkthrough of the same OpenEnv + TRL stack).
- Everything in one place: the SmolDataEnvs Multi-harness RL collection.
The current tutorial uses upstream trainers and Daytona sandboxes, so it is not an exact replay of the reported E2B runs; its VALIDATION.md records what has been re-checked.