The grading primitive
SandboxAPI tells you whether the sandboxed run completed, failed, or timed out. Your harness owns the domain verdict: which tests passed, what feedback to show, and how to score the submission.
Single-call grading with a harness
For interview-style problems, send a small wrapper that combines the candidate's function with your hidden tests and prints a machine-readable verdict.
# The harness runs inside the sandbox and prints JSON.
curl -X POST https://sandboxapi.p.rapidapi.com/v1/execute \
-H "X-RapidAPI-Key: $KEY" \
-d '{
"language": "python3",
"timeout": 30,
"code": "import json\n\ndef solve(nums):\n return sum(nums)\n\ncases = [([1,2,3], 6), ([10,-4], 6)]\npassed = sum(1 for inp, exp in cases if solve(inp) == exp)\nprint(json.dumps({\"passed\": passed, \"total\": len(cases)}))"
}'
Verdict in one round trip
The API response gives you execution metadata and the harness output. Your product maps that into candidate-facing feedback.
{
"id": "exec_xyz",
"status": "completed",
"language": "python3",
"stdout": "{\"passed\":2,\"total\":2}\n",
"stderr": "",
"exit_code": 0,
"execution_time_ms": 187,
"memory_used_kb": 12544,
"timeout": 30,
"created_at": "2026-06-25T10:00:00Z"
}
Map status straight into your candidate-facing UI:
completed→ parse stdout and show "Passed 7 of 10 cases."error→ show a safe excerpt of stderr and exit code.timeout→ "Your solution exceeded the time budget. Optimize and retry."
Multi-language support
The same endpoint runs Python, JavaScript, TypeScript, Bash, Java, C, C++, and Go. Keep one API integration and swap the language field plus your per-language harness template.
End-to-end Python example
import requests
import json
def build_python_harness(candidate_code: str) -> str:
return f"""{candidate_code}
import json
cases = [([1, 2, 3], 6), ([10, -4], 6)]
passed = sum(1 for inp, exp in cases if solve(inp) == exp)
print(json.dumps({{"passed": passed, "total": len(cases)}}))
"""
def grade_python(candidate_code: str, time_limit=10):
payload = {
"language": "python3",
"code": build_python_harness(candidate_code),
"timeout": time_limit,
}
r = requests.post(
"https://sandboxapi.p.rapidapi.com/v1/execute",
headers={"X-RapidAPI-Key": API_KEY, "Content-Type": "application/json"},
json=payload,
)
return r.json()
# Grade a candidate's solution
result = grade_python(candidate_code)
# Map verdict to candidate-facing message
if result["status"] == "completed":
verdict = json.loads(result["stdout"])
print(f"Passed {verdict['passed']} of {verdict['total']} cases.")
elif result["status"] == "timeout":
print("Time limit exceeded.")
else:
print("Code failed:", result["stderr"][:500])
Why teams pick SandboxAPI for assessments
- Predictable latency — pre-warmed sandboxes keep short submissions responsive.
- Modern runtimes — your candidates can solve in Python 3.12 or Node 22, not 2018-era stacks.
- Batch execution — run many submissions or examples through one endpoint, capped by plan.
- Streaming output — show candidate progress while longer tests run.
- Session workflows — keep files and installed packages available across iterative runs.
- gVisor isolation — candidate code runs inside a user-space kernel sandbox. Even if a candidate tries to bypass your time limit, syscall filtering stops it.