Best-of-N without paying for N setups: the source sandbox gets slug.py (a slugify with four bugs), test_slug.py (seven tests, five of which fail) and fix.py, then forks into three copies that start from its memory and disk. Each fork asks the node's model for a fix at its own temperature (0, 0.6 and 1.0), runs the tests on the answer and, if they still fail, sends the new output back once. The lowest temperature whose fix passes wins.

Check

Verified 2026-11-06: this recipe's last run passed against https://beta-api.b3os.org, label live-recorded (recorded from production), from commit 9fd4273e. The recipe harness runs it again, and a failed run takes this page out of the cookbook.

Run it

Each tab uploads the three files from this recipe's folder, forks once into three copies and runs fix.py in each at its own temperature.

bash
API=https://beta-api.b3os.orgAUTH="Authorization: Bearer $B3OS_API_KEY"post() { curl -s "$API$1" -H "$AUTH" -H "Content-Type: application/json" -d @-; }SRC=$(echo '{"template": "base", "timeout_s": 300, "forkable": true, "egress": {"mode": "deny"}, "api": {"scopes": ["infer:run"], "spend_cap_usd": 1}}' | post /v1/sandboxes | jq -r .id)for f in slug.py test_slug.py fix.py; do curl -s -X PUT "$API/v1/sandboxes/$SRC/files?path=/workspace/$f" -H "$AUTH" \ -H "Content-Type: application/octet-stream" --data-binary @"$f" > /dev/nulldoneecho '{"cmd": ["python3", "/workspace/fix.py", "--tests-only"]}' | post "/v1/sandboxes/$SRC/exec" | jq -r .stdout# Three copies of the source's memory and disk, then one try per temperature, at onceFORKS=$(echo '{"count": 3}' | post "/v1/sandboxes/$SRC/fork" | jq -r '.data[].id')i=0for id in $FORKS; do i=$((i + 1)) t=$(echo "0 0.6 1.0" | cut -d' ' -f$i) jq -n --arg t "$t" '{cmd: ["python3", "/workspace/fix.py"], env: {TEMPERATURE: $t}, timeout_ms: 58000}' \ | post "/v1/sandboxes/$id/exec" | jq -r '.stdout | split("\n") | map(select(. != "")) | last' &donewaitfor id in $SRC $FORKS; do curl -s -X DELETE "$API/v1/sandboxes/$id" -H "$AUTH" > /dev/null; done

The forks inherit the source's grant (infer:run with its $1 spend cap, so OPENAI_BASE_URL points at the node's model) and its egress (deny). Each fork changes only its own copy of slug.py; the source and the other forks never see it. Which temperatures pass changes from run to run: the recipe asserts the setup (seven tests, five failing, three forks that each ran), not the model's answers. fork_ms and fork_restore_ms are the fork's server-side total and restore phase from its Server-Timing header; model_ms and tests_ms are measured inside each fork. All four sandboxes are deleted at the end.

Files: run.mjs (the client), slug.py, test_slug.py and fix.py (uploaded to the source sandbox).

Owner: Sandboxes. Products: Sandboxes, Infer.

Output of the last green run

json
{ "tests_total": 7, "failing_before": 5, "forks": 3, "fork_ms": 52.118, "fork_restore_ms": 27.921, "passing": 2, "winner_temperature": 0, "tries": [ { "temperature": 0, "passed": true, "tests_passed": 7, "rounds": 2, "model_ms": 3197.7, "tests_ms": 37.7, "lines": 27, "failing": [] }, { "temperature": 0.6, "passed": true, "tests_passed": 7, "rounds": 2, "model_ms": 2734, "tests_ms": 73.5, "lines": 26, "failing": [] }, { "temperature": 1, "passed": false, "tests_passed": 6, "rounds": 2, "model_ms": 4240.6, "tests_ms": 28.6, "lines": 34, "failing": [ "test_accents" ] } ]}

The outputs this recipe publishes (the publish.outputs list in its recipe.json), with workspace identifiers redacted. The run's stdout, stderr and other outputs are not published.

Captured 2026-11-06 from commit 9fd4273e , label live-recorded (recorded from production). Case recipes/sandbox-fork-best-of-n-fixes .

Ask a question... ⌘I