Score model-written code in 100 sandboxes at once
Dec 2, 2026 · 6 min read
Score an open model on all 164 HumanEval problems from one script and one API key, with every solution running in a VM of its own, 100 at a time.
Model-written code is untrusted code. Run it in your own process and one bad solution can delete files, hang the run or read your API keys. So eval and RL pipelines run each attempt in a fresh sandbox, which puts sandbox start time inside every eval's wall clock.
This tutorial scores openrelay/glm-5.3 on HumanEval, OpenAI's set of 164 Python problems with unit tests. OpenRelay's inference API writes the solutions, and each one runs in its own OpenRelay sandbox, a Firecracker VM that starts in a median of 81 ms. The same key pays for the model and the sandboxes.
You need Python 3.11 or later and an OpenRelay account. The script is about 70 lines.
How it works
The script runs in three steps, and only the second one touches a sandbox.
- Generate. 32 threads ask
openrelay/glm-5.3to complete each problem's function, through the OpenAI-compatible API atinference.openrelay.inc. - Execute. For each solution the script builds one program: the problem's prompt, the model's function, HumanEval's tests and a call to
check(). It starts a sandbox whose first command runs that program with a 10-second limit. 100 threads keep up to 100 sandboxes running at once. - Grade. Exit code 0 means every assertion passed. Anything else is a fail, including a timeout, which exits with 124. The sandbox is killed either way.
Each solution gets a clean VM, so a solution that fills the disk, forks forever or deletes / fails alone. Nothing it does reaches the next one or your machine.
The script
Create an API key in the dashboard with two permissions: Inference: Use, to generate the solutions, and Sandboxes: Write, to run them. Then install the two SDKs and set the key:
pip install openrelay-sdk openai export OPENRELAY_API_KEY="or_your_api_key"
Save this as score.py:
"""Score an open model on HumanEval, running each solution in its own OpenRelay sandbox."""
import base64
import gzip
import json
import os
import re
import time
import urllib.request
from concurrent.futures import ThreadPoolExecutor
from openai import APIError, OpenAI
from openrelay.sandbox import Sandbox
MODEL = "openrelay/glm-5.3"
DATA = "https://github.com/openai/human-eval/raw/master/data/HumanEval.jsonl.gz"
llm = OpenAI(base_url="https://inference.openrelay.inc/v1", api_key=os.environ["OPENRELAY_API_KEY"])
def load_problems() -> list[dict]:
with urllib.request.urlopen(DATA) as response:
return [json.loads(line) for line in gzip.decompress(response.read()).splitlines()]
def generate(problem: dict) -> str:
try:
reply = llm.chat.completions.create(
model=MODEL,
max_tokens=32_000,
messages=[{
"role": "user",
"content": "Complete this Python function. Answer with the whole function "
"in one ```python block and nothing else.\n\n" + problem["prompt"],
}],
)
except APIError as error:
print("no answer for", problem["task_id"], error)
return ""
text = reply.choices[0].message.content or ""
match = re.search(r"```(?:python)?\n(.*?)```", text, re.DOTALL)
return match.group(1) if match else text
def run_tests(problem: dict, solution: str) -> bool:
program = "\n".join([problem["prompt"], solution, problem["test"], f"check({problem['entry_point']})"])
encoded = base64.b64encode(program.encode()).decode()
cmd = f"echo {encoded} | base64 -d > /tmp/solution.py && timeout 10 python3 /tmp/solution.py"
sb = Sandbox.create(template="python", run=cmd, timeout=60, ephemeral=True)
try:
return sb.result.exit_code == 0
finally:
sb.kill()
problems = load_problems()
start = time.monotonic()
with ThreadPoolExecutor(max_workers=32) as pool:
solutions = list(pool.map(generate, problems))
print(f"generated {len(solutions)} solutions in {time.monotonic() - start:.1f} s")
start = time.monotonic()
with ThreadPoolExecutor(max_workers=100) as pool:
passed = list(pool.map(run_tests, problems, solutions))
print(f"ran {len(passed)} test suites in {time.monotonic() - start:.1f} s")
print(f"pass@1: {sum(passed)}/{len(passed)} = {sum(passed) / len(passed):.1%}")
for problem, ok in zip(problems, passed):
if not ok:
print("failed", problem["task_id"])The parts worth a second look:
generateasks for the whole function and pulls it out of the reply's code block. The program puts the original prompt first, so the problem's imports are there even when the model leaves them out, and the model's function replaces the stub.max_tokens=32_000stops the model on the rare problem it reasons about for tens of thousands of tokens, which bounds how long generation can take. A reply cut short or an API error leaves that problem with no solution, so it counts as a fail instead of stopping the run.run_testssends the program as base64 inside the sandbox's first command (run=), so nothing has to be uploaded.Sandbox.createreturns once that command exits, with its exit code insb.result.timeout=60caps each sandbox's life at a minute even if your script dies mid-run, andephemeral=Truekeeps 164 short-lived sandboxes out of your history.- The SDK is safe to share across threads, so the 100 workers need no setup of their own. If your organization reaches its limit on running sandboxes, the API answers
429and the SDK waits out theRetry-Afterand tries again.
Run it:
python score.py
What we got
In two runs of the script, openrelay/glm-5.3 passed 162 and 164 of the 164 problems, a pass@1 of 98.8% and 100.0%. That comes from this script's prompt and settings, so it is not comparable with HumanEval scores published under other prompts. Current models solve nearly all of HumanEval, which makes it a good first test of the harness and a weak test of the model: swap in harder tasks once it runs.
Generation took 309 s and 251 s. Most of that is the last few problems, where the model reasons for thousands of tokens before it answers. All 164 test suites ran in 1.7 s both times.
Data
| Workers | All 164 | Median sandbox | p90 | Slowest | Passed |
|---|---|---|---|---|---|
| 1 | 25.15 s | 94 ms | 104 ms | 297 ms | 163 of 164 |
| 10 | 2.64 s | 96 ms | 121 ms | 237 ms | 163 of 164 |
| 20 | 1.63 s | 108 ms | 162 ms | 285 ms | 163 of 164 |
| 100 | 1.69 s | 217 ms | 1113 ms | 1,329 ms | 163 of 164 |
Each sandbox took a median of 94 ms from the create call to the test's exit code, so one at a time the test step is a series of short waits: 25.15 s for 164 sandboxes. With 20 at a time it took 1.63 s, 15.4 times faster, and 100 at a time took about the same, 1.69 s. Tests this short leave little for more workers to do, and with 100 the slowest tenth of sandboxes took 1.1 s or more each. The extra workers pay off when each test runs for seconds instead of a tenth of one.
What it costs
The built-in python template has 2 vCPUs and 2 GiB of memory, which is $0.1584 an hour at $0.0594 per vCPU-hour and $0.0198 per GiB-hour, billed by the second. Each sandbox lived about 0.15 s from create to kill, so even counted as the whole machine for that long, all 164 come to at most $0.0011 at the published rates. The meter bills each second at the greater of what a sandbox requested and what it used, so short, mostly idle sandboxes like these cost less. Sandbox pricing has the current rates.
The tokens cost far more than the sandboxes. Generating the 164 solutions wrote about 338,000 output tokens, most of them the model's reasoning, from 26,494 input tokens. That came to about $1.02 a run at glm-5.3's rates on December 2, 2026. The inference pricing page lists every model's rates.
Next steps
run_tests is already a reward function: it returns pass or fail for one attempt, in a VM of its own.
- Use it in RL. Call
run_testsfrom your trainer's rollout loop and score 1.0 for a pass. Thousands of rollouts a step are thousands of short-lived sandboxes, the shape this script already has. - Grade your own tasks. Replace
load_problemswith your test set. A task that needs other tools or languages runs on a template you build, and the rest of the script stays as it is. - Evaluate agents, not completions. Give each task a sandbox with
model=set, let Claude Code work on a repository inside it, then run the repository's tests as the grade.
Score a model
Create a key with Inference: Use and Sandboxes: Write, and run score.py.
The sandbox guide covers templates, files, ports and the rest of the API.