onlinecompiler.io

Run tests: judge code against test cases

POST /api/run-tests/ runs one program against a list of tests, each in a fresh sandbox, and returns a verdict for each test, an overall verdict and a score from 0 to 100. Hidden tests come back with only their verdict, and each test counts as one run.

POST https://api.onlinecompiler.io/api/run-tests/

Run one program against a list of tests and get a verdict for each, an overall verdict and a score, in one request. It authenticates like the sync endpoint and waits for the result, unless you ask for asynchronous judging. Each test runs in its own fresh sandbox, and each test counts as one run against your monthly allowance and your per-minute and pending limits. For a synchronous request, each test takes one of your account's pending slots when the request arrives and frees it when that test finishes, so on Free one 32-test request starts out using all of them, and your other runs (the widget's included) wait or get 429 until its tests start finishing.

The official clients send this request for you: client.runTests({ compiler, code, tests }) in Node.js (npm install onlinecompiler) and client.run_tests(compiler, code, tests=[...]) in Python (pip install onlinecompiler). With async, waitForSubmission and wait_for_submission look the result up until it is ready. See the Node.js client and Python client.

FieldTypeRequiredDescription
compilerstringYesA compiler id, as on the other endpoints.
codestringYesSource code (max 100KB). Compiled in every test, or once per request for C, C++ and Java when there are more tests than run at once.
testsarrayYesThe tests to run, 1 up to your plan's limit (table below).
tests[].inputstringNoStandard input for this test (max 5 MB). Empty if left out.
tests[].expected_outputstringYesWhat the program should print (max 64KB). Stderr is never compared.
tests[].hiddenbooleanNofalse if left out. A hidden test returns only its verdict.
tests[].weightnumberNoAbove 0; 1 if left out. Counts only for weighted scoring.
tests[].argsarrayNoCommand-line arguments the program gets in this test, exactly as sent: up to 32 strings and 4,096 bytes in all. Not for sqlite-3, duckdb-1.5 or erlang-29. They are part of the receipt's tests hash.
time_limitnumberNoSeconds each test may run, above 0 and up to 30; 2 if left out. Java, Groovy and F# get a start-up allowance on top (see below).
memory_limitintegerNoMB each test's program may use at its peak, one value for every test: a whole number from 16 to 2048; above 512 it raises the sandbox's cap, on Pro and above or with an exam tier (Free and Starter get a 400 that names the plan). A test over it is memory_limit_exceeded. Without it, the sandbox's 512 MB applies. See memory limit on the run-code page.
filesarrayNoFiles shared by every test, each {name, content, encoding} as on the run endpoints: up to 20 files and 1 MB in total. Helper source files reach the compile step too, so a header and its .c file work in every test (see several source files on the run-code page). Every test's sandbox gets its own copy in the working directory.
suiteobjectNoRun a test pack's own test suite over files instead of code against tests: {"preset": "pytest"} or {"command": "..."}, with "services": ["postgresql"] to start a database first. code and tests are then not sent. See Test suites below.
checkerstringNoHow output is compared: trim (the default), exact, tokens, float, rows, table or table_ordered.
tolerancenumberNoFor the float, rows, table and table_ordered checkers: 0 to 1; 1e-6 if left out.
scoringstringNoall_or_nothing (the default), percent or weighted.
stop_on_failurebooleanNoStop starting tests after the first one that is not accepted. true with all_or_nothing, false otherwise.
asyncbooleanNotrue answers 202 at once and judges the submission in your account's queue (see Asynchronous judging below). false if left out.
callback_urlstringNoA public http(s) URL that receives the result as a signed webhook; implies async: true. Up to 2,000 characters, no credentials, redirects not followed. See Webhooks.
external_refstringNoYour own id for the submission, such as an attempt id, up to 200 characters. It comes back in lookups and webhooks and is signed into the receipt. Use an opaque id, never an email address or a name: sharing a receipt publishes it.
metadataobjectNoAny JSON object up to 4 KB. It comes back in lookups and webhooks, never in receipts.
Idempotency-KeyheaderNoUp to 100 printable ASCII characters. Repeating a request with the same key answers with the original result instead of running again (see Retrying safely below).

Limits for one request

PlanTests per requestRun at onceMost tests at the default time_limit
Free32432
Starter60860
Pro12010100
Business24020200
Platform600100600

The last column is for a language with the default round overhead of 3 seconds and no start-up allowance, such as Python or C++. Languages that compile slowly fit fewer tests (see below).

  • The number of tests is capped by your plan's pending limit. Tests run in the order you list them, at most as many at once as the table shows, and never more than your plan's runs at once.
  • One request has a 60-second budget. Tests run in rounds (tests divided by tests at once, rounded up), and a round takes up to time_limit + start-up allowance + the language's round overhead for compiling and starting. All the rounds must fit in 60 seconds, and the last must be able to start within 45. A request over budget gets 400 with the largest time_limit that would fit.
  • The round overhead is 3 seconds, except for languages that compile slowly: Crystal (13 s), Kotlin (6 s), Nim (5.5 s), Zig (4.5 s), Scala (4 s), C# (4 s) and Visual Basic (4 s). Each test compiles the program again, so these fit fewer tests; at the default time_limit, a Crystal request holds at most 40 tests on Pro.
  • C, C++ and Java compile once per request when there are more tests than run at once: one sandbox compiles the program, without any test input, then each test runs the build in its own fresh sandbox. If a C or C++ compile fails, the first test gets the verdict and counts as one run, and the rest are skipped; a Java program that fails to compile runs as before, compiling in every test. A request whose tests all run at once compiles in every test, which is faster for so few tests.
  • No test starts after 45 seconds from the request's arrival. Tests that never started are skipped, are not counted as runs and leave no history. When the cut-off skipped tests and none failed, the overall verdict is incomplete. The budget leaves time for every round, so this usually means tests waited for a sandbox, held by other users or by your account's other runs: retry the request. A retry runs, and counts, every test again. Such a result does not keep its Idempotency-Key, so a retry with the same key runs again. An async submission whose tests could not all start in time is not fully judged: it ends failed instead, with the error "Not every test could start in time. Send the submission again."
  • A compilation error stops the remaining tests, because they would fail the same way. With stop_on_failure, the first test that is not accepted does too.
  • Inputs and expected outputs together may hold at most 32 MB. The shared files have their own limit of 20 files and 1 MB.
  • Output files come back on visible tests only, and a hidden test never returns any. One response holds at most 4 MB of file content in all; tests after that get files_truncated: true and no files. Each file has url set to null here: use the run endpoints when you need a stored copy.
  • A bad request answers 400 with {"error": "..."} and starts nothing. Account limits and a busy service answer 429, and nothing runs.

Verdicts

Each test gets one verdict, decided in the order of this table (accepted and wrong_answer last). The last column is the Judge0 status id it maps to.

VerdictWhenJudge0 id
internal_errorWe could not run the test.13
compilation_errorCompiling failed (languages with a compile step; a syntax error in an interpreted language is a runtime_error).6
time_limit_exceededExit code 124, or the run took longer than the time limit plus any start-up allowance.5
memory_limit_exceededExit code 137: killed at the sandbox's 512 MB or at a higher memory_limit, or its peak went over a lower memory_limit, when error ends with how much it used. Judge0 has no memory status, so it reports 12.12
output_limit_exceededSignal 25, or stdout was cut at 64KB.8
runtime_errorAny other non-zero exit code or signal.7 to 12
wrong_answerExit code 0 and the checker rejects the output.4
acceptedExit code 0 and the checker accepts the output.3
skippedThe test never started: the program failed to compile, or failed with stop_on_failure, or the start cut-off came first. Test entries only; it counts as not accepted.none
incompleteOverall verdict only: the start cut-off skipped tests and none failed, usually because the service was busy or your account's other runs kept its sandboxes busy. Retry the request, with the same Idempotency-Key if you sent one.none

Checkers and scoring

checkerCompares
trimStrips trailing whitespace from every line and trailing blank lines, then compares exactly. The default; it is what Judge0 does.
exactThe two outputs are identical, byte for byte.
tokensSplits both on whitespace and compares the lists, so spacing and line breaks do not matter.
floatAs tokens, but two numbers match when they differ by at most tolerance times the larger of 1 and the expected value. Anything that is not a finite number must match as text.
rowsFor SQL and pandas questions where row order is not part of the answer. Trims like trim, then compares the lines as an unordered set (the same line twice must appear twice). A line that has |, a comma or a tab is split at each one into fields, with spaces around a field ignored and empty fields kept, so Bob| and Bob differ and 1, 2 equals 1,2; any other line is split at whitespace. Numbers match within tolerance as in float, and every other field must match as text.
tableFor pandas and SQL answers printed as a CSV table with a header row, such as print(df.to_csv(index=False)) or SQLite and DuckDB in CSV mode with headers. Both outputs are read as CSV, so a quoted field may hold commas or line breaks. Columns are matched by name, so their order does not matter (when a name repeats, columns compare in order), and rows match in any order. A first column with an empty name, the index pandas writes by default, is ignored when the expected table has none. Cells are compared without surrounding spaces; empty, NaN, None, NULL, <NA> and NaT all count as missing and match each other; true and false match in any case; numbers match within tolerance as in float. Output that is not a table, or a row with the wrong number of fields, is a wrong answer.
table_orderedAs table, but the rows must come in the expected order, for answers that sort them.
scoringscore
all_or_nothing100 when every test is accepted, otherwise 0.
percent100 times accepted tests over all tests.
weighted100 times the weights of accepted tests over all weights.

Response (200)

FieldDescription
verdictThe overall verdict: accepted when every test is, otherwise the verdict of the first test (in your order) that failed. incomplete when tests were skipped only by the 45-second start cut-off, usually because the service was busy or your account's other runs kept its sandboxes busy; retry the request, with the same Idempotency-Key if you sent one.
scoreFrom 0 to 100, rounded to 2 decimals. Skipped tests count as not accepted.
passed, totalTests accepted, and tests sent.
time_limitThe time limit used, in seconds, without the start-up allowance.
memory_limitThe memory limit used, in MB: memory_limit, or 512 without one (always so for a stored problem).
compile_errorThe compiler output (first 4096 characters) when the code failed to compile and at least one test is visible; null otherwise. A request that compiles in every test takes it from the first visible test that failed to compile, so there it is also null when only hidden tests did.
testsOne entry per test, in the order sent. Each has verdict and hidden. A visible test that ran also has time, memory, exit_code, signal, output, error, truncated, files and files_truncated; files is an empty list when the program wrote none.
summaryThe result in plain words, like "1 of 2 sample tests passed. Sample 2 printed a wrong answer." Hidden tests add counts only.
submissionThe submission's id, like sub_8f2Kq7LmT3xR9vWb1cYd4hNe. Every request is stored as a submission.
receiptThe signed receipt (see Receipts), or null when none could be signed.
Response
{
  "verdict": "runtime_error",
  "score": 33.33,
  "passed": 1,
  "total": 2,
  "time_limit": 2,
  "memory_limit": 512,
  "compile_error": null,
  "tests": [
    {"verdict": "accepted", "hidden": false, "time": "0.0213", "memory": "9000",
     "exit_code": 0, "signal": null, "output": "3
", "error": "", "truncated": false},
    {"verdict": "runtime_error", "hidden": true}
  ],
  "summary": "1 of 1 sample test passed. 0 of 1 hidden test passed.",
  "submission": "sub_8f2Kq7LmT3xR9vWb1cYd4hNe",
  "receipt": {"receipt": "rcpt_7Hq2Zp4Wn8Ks1Ab6Ct3Dv5Ex", "format": 1, "verdict": "runtime_error", "...": "see Receipts", "key_id": "oc-2026-11", "signature": "FmOjS6fP...pOuCBQ=="}
}

Inputs and expected outputs are not sent back. output and error are cut to the first 4096 characters, and truncated is true when either was cut. time and memory are strings, as on the sync endpoint. The response above is for the examples below: the hidden test puts the two numbers on separate lines, which the program does not read, so it ends in a runtime_error and the score is 1 of 3 weight points.

Hidden tests return only their verdict. A hidden test, and a skipped one, comes back as {"verdict": ..., "hidden": ...} and nothing else: no output, error, exit code, time or memory. Compiler output from a compile that saw a hidden test's input never appears in compile_error; a request that compiles once compiles without any test input, so a failed compile's output appears in compile_error whenever a test is visible. A program can encode a hidden input in anything it controls, so a student's code cannot read a hidden test back through your results.
Keeping the tests on the server? Stored problems hold a problem's tests, drivers and checker for you and judge code against it by id, so a candidate sends only code and never sees a hidden test.

Asynchronous judging

Send async: true, or a callback_url, to get a 202 at once instead of waiting. The submission is queued, and you get its result from a signed webhook or by looking it up.

Terminal
curl -X POST https://api.onlinecompiler.io/api/run-tests/ \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: attempt-4821" \
  -d '{
    "compiler": "python-3.14",
    "code": "a, b = map(int, input().split())\nprint(a + b)",
    "tests": [{"input": "1 2\n", "expected_output": "3\n"}],
    "async": true,
    "callback_url": "https://example.com/hooks/oc",
    "external_ref": "attempt-4821"
  }'
Response (202)
{"submission": "sub_8f2Kq7LmT3xR9vWb1cYd4hNe", "status": "queued"}
  • It is accepted while your monthly allowance and the API key's monthly limit cover all its tests, counting the tests of your other queued submissions, and your account has fewer than the queue cap queued: 320 on Free, 600 on Starter, 1,200 on Pro, 2,400 on Business, 6,000 on Platform (10 times the plan's pending limit). Otherwise it answers 429 and nothing is queued.
  • Your account's queued submissions may hold at most 64 MB of request data in all, on every plan; a submission that would pass that is refused with 429 until queued ones finish.
  • A submission with more tests than your plan's per-minute limit is refused with 429, because it could never start. On Free, once 320 are queued, the next is refused with 429.
  • Your account's queued submissions are judged one at a time, in the order they arrived: the next waits for the previous to finish. Each starts only when your per-minute and pending limits have room for all its tests; those limits pace when queued work starts, so a burst waits instead of getting 429.
  • Nothing is charged until a submission starts, and then it is charged for all its tests at once, one run each. Tests that never start are refunded.
  • A submission that cannot start because something changed while it waited, such as a deleted API key, a lower plan or a spent allowance, ends failed with the reason in error, and is not charged.
  • A submission whose tests could not all start within the 45-second start cut-off, usually because the service was busy, ends failed with the error "Not every test could start in time. Send the submission again." The tests that ran are charged; the ones that never started are not.
Plan a deadline from the per-minute limit. 200 candidates with 10 tests each is 2,000 runs. At Pro's 600 runs a minute, the last result cannot come sooner than 3 minutes after the submissions are sent. That is a floor from the plan's arithmetic, not an estimate: it may take longer, never less.

Looking up, listing, deleting and sharing

  • GET /api/submissions/{id}/ returns the submission: status (queued, running, finished or failed), created, finished, external_ref, metadata, for a stored problem's submission its problem and mode (all, samples or tests; null for plain run-tests), rejudge_of (for a re-judge, the submission it judges again; otherwise null), and once done the result and receipt, and hash_salt, which the receipt's test and file hashes are salted with (only this lookup returns it; see Receipts). Another account's id, or a malformed one, answers 404. Output files are not kept, so a test that returned files lists none.
  • GET /api/submissions/ lists your submissions, newest first, 20 a page (up to 100 with limit). Filter with external_ref (one candidate's, a widget session's included), problem (a stored problem's id or slug, any version), status, verdict, since and until (ISO 8601, UTC when there is no offset; since includes its moment and until does not), or ids (up to 100 ids, separated by commas, all on one page unless you send limit); they combine. Each entry is a summary: submission, status, created, finished, external_ref, metadata, problem, mode, rejudge_of, the result's verdict, score, passed and total (null until it has finished), and error for a failed one; fetch a submission by its id for its tests and receipt. While next_cursor is not null, send it back as cursor, with the same filters, for the next page. Draft tests, reference checks and Submits under a test session made in the dashboard (your own tries) are not listed, though each is still found by its id. A parameter the list does not take answers 400. The Node.js and Python clients follow the cursor for you: iterSubmissions() and iter_submissions() go through every page, submissions() gives one.
  • failed means the submission was not judged: error says why (a deleted or disabled API key, a lower plan, a spent allowance, tests that could not all start in time, or our side). When it says to send it again, sending again, with the same key or a new one, runs it.
  • DELETE /api/submissions/{id}/ deletes a queued, finished or failed submission, with the code, input and output kept for its tests and the output files of its tests. A queued one never runs. A running one answers 409: delete it once it has finished. Runs already counted stay counted, and deleting frees its Idempotency-Key.
  • POST /api/submissions/{id}/share/ makes the receipt public at a link. Sharing publishes the receipt, including external_ref and an account reference, and never the code, tests, outputs or metadata, so use an opaque external_ref, never an email or a name. A Submit made in the widget under a session is shared when it is made unless the session says share_receipts: false. See Receipts.
  • Submissions are kept for 90 days on Free, 365 days on Starter, 730 days on Pro, 730 days on Business, 730 days on Platform.
  • The Submissions page of your dashboard lists your judged submissions, newest first, filtered by problem, verdict, status, API key, or a submission's id or external_ref; a stored problem's submission shows which of its tests it ran (all, the samples or chosen tests). A submission's page shows what GET /api/submissions/{id}/ returns to you (hidden tests as verdicts only), with its code, its checker log, its receipt to download as JSON and its webhook deliveries, and deletes it as DELETE does. A re-judge's page links to the submission it judged again, and that submission's page links to its re-judges.
One candidate's submissions
curl "https://api.onlinecompiler.io/api/submissions/?external_ref=candidate-8841&limit=50" \
  -H "Authorization: YOUR_API_KEY"

Retrying safely

Send an Idempotency-Key header, such as your attempt id, so that a retry after a timeout cannot judge the same submission twice.

  • A request that repeats a key your account sent in the last 24 hours, with the same body, runs nothing and is not counted. It answers with the original result and the header Idempotent-Replayed: true, or with 202 and the submission's current status when the original is async or still running. Bodies are compared as JSON, so key order and spacing do not matter.
  • The same key with a different body answers 409; nothing runs. Use a new key for a new request.
  • Output file contents are not kept, so a replayed result lists no files.
  • A request refused with 400 or 429 does not use up its key. A submission that ends failed frees its key, so sending again with the same key runs it again. So does a sync result in which the start cut-off skipped tests: sending it again with the same key runs it again.
  • A retry sent while the original is still being accepted can briefly get 202 running for an original that is then refused. That id then answers 404, and sending again runs it.

Next: Webhooks for the signed result and Receipts for proof of a verdict.

Start-up allowance for Java, Groovy and F#

These three compile as they start, inside the timed run, so even a hello-world uses part of a small time_limit. They get extra seconds on top of the limit: Java (1 s), Groovy (1.5 s) and F# (2.5 s). The run is stopped at time_limit plus the allowance, and a test is time_limit_exceeded only past that. time is still reported as measured, start-up included, and the response's time_limit is the one you asked for. The allowance applies wherever a time limit is honoured: here, the native time_limit on the run endpoints, and the Judge0 and Piston layers. In run-tests requests that compile once, Java compiles before the timed run, so its time is lower there; the allowance still applies everywhere for now. We will remove it once compiling always happens before the timed run.

Grading pandas and SQL questions

Send the question's data once in files; every test gets it in its working directory. Have the program print one row per line and grade with checker: "rows", so a correct answer is not marked wrong for its row order. duckdb-1.5 works like sqlite-3: the program is the SQL, it prints rows as a|b|c with no header, and it reads the test's input with read_text('input').

Terminal
curl -X POST https://api.onlinecompiler.io/api/run-tests/ \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "duckdb-1.5",
    "code": "SELECT region, sum(amount) FROM read_csv('\''sales.csv'\'') GROUP BY region;",
    "files": [
      {"name": "sales.csv", "content": "region,amount\nnorth,10\nsouth,20\nnorth,5.5\n"}
    ],
    "tests": [
      {"expected_output": "south|20.0\nnorth|15.5\n"}
    ],
    "checker": "rows"
  }'

Set a larger time_limit for heavy imports. Python has no start-up allowance, so the default of 2 seconds also has to cover imports. On the dev PC, pandas takes about 0.55 s to import, scikit-learn about 1.5 s, and the whole stack about 3 s. For a pandas or scikit-learn question, start with a time_limit of 10 seconds. A longer limit means fewer tests fit the request's 60-second budget.

Test suites: pytest, Jest, Mocha, node:test, JUnit, xUnit and NUnit

Send suite instead of code and tests to run a project's own tests. The code under test, its test files and any fixtures go in files; a test pack runs its test command over them in one sandbox, and the answer names every test with its own status. A suite counts as one run against your limits, however many tests it holds. Worked examples (a Flask app with pytest, an Express API with Jest, points per test) are on the pytest and Jest autograder page, and Java with JUnit, with a script that grades a whole class, on the Java autograder page.

compilerPresets (the first is the default)Includes
python-3.14-testspytestpytest (which also runs unittest tests), Flask, Flask-SQLAlchemy, SQLAlchemy, FastAPI with httpx, PyJWT and psycopg, beside the data-science stack of python-3.14
nodejs-24-testsjest, mocha, node-testJest, Mocha with Chai, node:test, Supertest, Express, jsonwebtoken, bcrypt and pg
openjdk-25-testsjunitJUnit Jupiter (JUnit 5 and 6) and JUnit 4 through the JUnit Platform console launcher, with AssertJ and Mockito
dotnet-csharp-10-testsxunit, nunitxUnit v3 and NUnit 4 (through NUnitLite), compiled with the C# compiler and run in one process
  • suite is {"preset": "pytest"} or {"command": "..."}, never both; {} runs the pack's default preset. GET /api/compilers/ lists each pack with a pack field: its version, presets, default and services.
  • Each preset runs every test in one process and finds tests the framework's usual way (Mocha: files under test/ and *.test.js; JUnit: every test class, whatever its name, JUnit Jupiter and JUnit 4 alike). Its JUnit report comes back parsed. pytest, Jest, Mocha, node:test and JUnit Jupiter stop any one test after 10 seconds (a JUnit 4 test, after its own @Test(timeout)); xunit and nunit have no per-test limit (xUnit v3 has none, and NUnit's works only on .NET Framework), so their tests run under the suite's time_limit only. A test's own xUnit Timeout still works. pytest, Jest, JUnit, xUnit and NUnit write the test runner's own output to run.error, so a test there that prints a lot is judged by its report: only output past 8 MB stops the run. (pytest has done so since pack 1.1; in 1.0 it wrote to run.output.) Mocha and node:test print nothing. From pack 1.1, jest, mocha and node-test end the run once their tests are done (--forceExit, --exit, --test-force-exit), so a database pool or server left open doesn't hold it until time_limit. Two lines those presets print whatever the tests do are left out of run.error: Jest's "Force exiting Jest" note, and Mocha's warning for a pattern no file matches when there is no test/ folder or no *.test.js file. A custom command's output comes back whole.
  • The Java and C# packs compile first: every .java or .cs file sent, in one compile. A failed compile answers compilation_error with no tests and the compiler's messages in run.error. C# test files compile as dotnet new xunit3 and dotnet new nunit projects do (the implicit usings and the framework's own), and a Main in the code under test is ignored. Code that ends the process (System.exit, Environment.Exit) leaves no report, so its answer is no_report; a compiler stopped by a signal answers internal_error. Write Java tests with single-type or static imports (import static org.assertj.core.api.Assertions.assertThat;), not import org.junit.jupiter.api.*;, and put C# tests in a namespace with using Assert = Xunit.Assert; inside it: otherwise a student's own class named Assertions or Assert takes the place of the real one.
  • command is your own command instead, run with bash in /sandbox where the files are, up to 4,000 bytes. It must write $OUTPUT_DIR/report.xml (JUnit XML, which most test runners can write) or $OUTPUT_DIR/results.json (Gradescope's format: tests, each with a name and either a status or a score and max_score); report.xml is read when both exist.
  • files holds every file the suite needs, in folders if you like (tests/test_calculator.py), within 20 files and 1 MB. On nodejs-24-tests the pack's packages are already in node_modules, so files under node_modules/ are refused, and a package.json is optional.
  • time_limit covers the whole suite: up to 30 seconds, 20 if left out. memory_limit, external_ref, metadata and Idempotency-Key work as for tests. tests, checker, tolerance, scoring, stop_on_failure and args are refused with 400, and so are async: true and callback_url: a suite runs synchronously.
  • The clients send it for you: client.runSuite({ compiler, files, suite: { preset: 'pytest' } }) in Node.js and client.run_suite(compiler, files, preset="pytest") in Python, version 0.8.0 or later (services from 0.9.0).
  • A suite run has its own 127.0.0.1, so a test can start a server and call it (Express with Supertest, a Flask or FastAPI app). Nothing outside the sandbox can be reached, as in every run.
  • A suite's tests and the code under test run in one process, as they do on your machine, so code written to cheat can read the test files and write the report itself. That suits practice, coursework and CI checks. For an exam or a contest, grade with tests or a stored problem, where the expected output never enters the sandbox.
  • A suite request ends within 60 seconds: it starts within 45 seconds of arriving, or earlier when its time_limit would end it later (a 30-second suite must start by 27 seconds, a Java one by 26 and a C# one by 26). When no sandbox comes free in time, the answer is 429 and nothing counts; send it again.
Terminal
curl -X POST https://api.onlinecompiler.io/api/run-tests/ \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "python-3.14-tests",
    "suite": {"preset": "pytest"},
    "files": [
      {"name": "calculator.py", "content": "def add(a, b):\n    return a + b\n"},
      {"name": "tests/test_calculator.py", "content": "from calculator import add\n\ndef test_add():\n    assert add(2, 3) == 5\n\ndef test_add_negative():\n    assert add(-1, -1) == -3\n"}
    ]
  }'

The answer (shortened):

JSON
{
  "verdict": "failed",
  "gradable": true,
  "passed": 1, "failed": 1, "errors": 0, "skipped": 0, "total": 2,
  "score": 50.0,
  "tests": [
    {"name": "test_add", "classname": "tests.test_calculator", "file": null, "status": "passed",
     "time": 0.001, "message": null, "score": null, "max_score": null},
    {"name": "test_add_negative", "classname": "tests.test_calculator", "file": null, "status": "failed",
     "time": 0.001, "message": "assert -2 == -3\n +  where -2 = add(-1, -1)", "score": null, "max_score": null}
  ],
  "run": {"exit_code": 1, "signal": null, "time": 0.9, "memory": 41236, "output": "", "error": "...", "truncated": false},
  "compiler": "python-3.14-tests",
  "preset": "pytest",
  "pack": {"version": "1.1"},
  "report_truncated": false,
  "time_limit": 20,
  "memory_limit": 512,
  "summary": "1 of 2 tests passed.",
  "submission": "sub_...",
  "receipt": {"...": "..."}
}
  • verdict: the run's own problem first (time_limit_exceeded, memory_limit_exceeded, output_limit_exceeded, runtime_error for too many processes, internal_error); then compilation_error when a Java or C# compile failed; then no_report when the command left no readable report, or one that names no tests; else accepted when the report names at least one test and every test passed, failed otherwise. A non-zero exit alone is no problem, since test runners exit 1 when a test fails. gradable is false for no_report and internal_error.
  • tests: the report's tests in its order, each with name, classname (its class, module or describe blocks, which Jest joins with " > "; JUnit names a test adds() in class SolutionTest, xUnit Namespace.Class.Method and NUnit Method, both in class Namespace.Class), file, status (passed, failed, error or skipped), time, message (the failure, error or skip message, first 4096 characters) and, from a results.json, score and max_score. It is empty when the run itself had a problem, and without a report. Up to 1,000 tests are read from a report of up to 2 MB; report_truncated says when there were more.
  • score: the percentage of tests passed, or for a results.json with scores, their total over the maximum; rounded to 2 decimals. run is the command's own exit, time, memory and output.
  • preset is the preset that ran (null for a command), and pack.version changes only when the pack's frameworks or libraries do, so a result says what graded it. The receipt signs the preset, a SHA-256 of the command that ran, the pack's version and, when the suite started any, its services.

PostgreSQL in a suite

Add "services": ["postgresql"] to suite on python-3.14-tests or nodejs-24-tests and a fresh PostgreSQL 18.6 server starts in the same sandbox before the tests, seeded from your SQL files. Tests of an app that talks to a real database (Flask with SQLAlchemy, Express with pg) run as they would on your machine, and nothing is kept after the run. Services are for accounts whose runs may keep 32 processes at once: Pro and above, and the exam tiers. Send a memory_limit of at least 1,024 MB with them, since the server's memory counts in the run's.

  • Connecting: user postgres with no password (a superuser inside the sandbox), database postgres, on 127.0.0.1 and ::1 port 5432 and a socket in /tmp. DATABASE_URL (postgresql://postgres@127.0.0.1:5432/postgres) and PGHOST, PGPORT, PGUSER and PGDATABASE are set, so psycopg, SQLAlchemy and Flask-SQLAlchemy in the Python pack, and pg in the Node pack, connect with no settings of their own.
  • Seeding: every file under db/ whose name ends in .sql runs through psql before the tests, in the byte order of their paths (db/01-schema.sql before db/02-data.sql), stopping at the first error. psql prints only warnings and errors, so a failed seed's message is easy to find.
  • Limits: 8 connections at once; a further one fails inside the test that opened it with sorry, too many clients already, and the run goes on. The data lives in /sandbox/.oc-pg, in the run's 256 MB working space, which it shares with your files and which counts as the run's memory; the empty server takes 31 MB of it, and a full database never stops the test report from being written (that run's run.memory reads 0). Temporary files stop at 64 MB. Times are in UTC and text sorts by code point. Starting the server and the seeds count in time_limit: about 0.3 seconds, 0.4 with a 10,000-row seed.
  • When it goes wrong: a server that did not start answers internal_error with PostgreSQL did not start: and the server log in run.error, an error on our side. A seed that fails answers no_report with Seeding db/<file> failed: and psql's message, such as the line of SQL to fix. Your command runs in a subshell after the server is up, so code under test that exits 69 reads as exit 1 and can't pass for a server that failed. For the same reason a custom command must be complete: an unterminated here-document is a syntax error there (no_report), where bash alone would only warn.
  • Only through services: a suite without services, like a plain run on a test pack, has no PostgreSQL in its sandbox, on any plan: the server's programs are left out and oc-postgres only prints that PostgreSQL is for suites that send "services": ["postgresql"], on Pro and above, so a custom command cannot start one either.
  • Refused with 400: PostgreSQL in a suite needs 32 processes at once: Pro and above (https://onlinecompiler.io/pricing); suite.services must be a list of service names, such as ["postgresql"]; suite.services: openjdk-25-tests offers no services; suite.services names postgresql twice; PostgreSQL in a suite needs memory_limit of at least 1024 MB: the server's memory counts in the run's. The pack's services are checked first, then the plan, then the memory.
Terminal
curl -X POST https://api.onlinecompiler.io/api/run-tests/ \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "python-3.14-tests",
    "suite": {"services": ["postgresql"]},
    "memory_limit": 1024,
    "files": [
      {"name": "db/01-numbers.sql", "content": "CREATE TABLE numbers (a integer, b integer);\nINSERT INTO numbers VALUES (2, 3);\n"},
      {"name": "test_numbers.py", "content": "import os\n\nimport psycopg\n\n\ndef total():\n    with psycopg.connect(os.environ[\"DATABASE_URL\"]) as conn:\n        return conn.execute(\"SELECT a + b FROM numbers\").fetchone()[0]\n\n\ndef test_adds():\n    assert total() == 5\n\n\ndef test_fails():\n    assert total() == 4\n"}
    ]
  }'

The answer (shortened); pytest's own output is in run.error:

JSON
{
  "verdict": "failed",
  "gradable": true,
  "passed": 1, "failed": 1, "errors": 0, "skipped": 0, "total": 2,
  "score": 50.0,
  "tests": [
    {"name": "test_adds", "classname": "test_numbers", "file": null, "status": "passed",
     "time": 0.012, "message": null, "score": null, "max_score": null},
    {"name": "test_fails", "classname": "test_numbers", "file": null, "status": "failed",
     "time": 0.01, "message": "assert 5 == 4\n +  where 5 = total()", "score": null, "max_score": null}
  ],
  "run": {"exit_code": 1, "signal": null, "time": 1.0752, "memory": 62556, "output": "",
          "error": ".F    [100%]\n=== FAILURES ===\n...\n1 failed, 1 passed in 0.14s\n", "truncated": false},
  "compiler": "python-3.14-tests",
  "preset": "pytest",
  "pack": {"version": "1.1"},
  "memory_limit": 1024,
  "summary": "1 of 2 tests passed.",
  "submission": "sub_...",
  "receipt": {"...": "...", "suite": {"preset": "pytest", "command_sha256": "...", "pack_version": "1.1", "services": ["postgresql"]}}
}

Examples

Terminal
curl -X POST https://api.onlinecompiler.io/api/run-tests/ \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "python-3.14",
    "code": "a, b = map(int, input().split())\nprint(a + b)",
    "tests": [
      {"input": "1 2\n", "expected_output": "3\n"},
      {"input": "5\n7\n", "expected_output": "12\n", "hidden": true, "weight": 2}
    ],
    "scoring": "weighted"
  }'
JavaScript
const res = await fetch('https://api.onlinecompiler.io/api/run-tests/', {
  method: 'POST',
  headers: { Authorization: 'YOUR_API_KEY', 'Content-Type': 'application/json' },
  body: JSON.stringify({
    compiler: 'python-3.14',
    code: 'a, b = map(int, input().split())\nprint(a + b)',
    tests: [
      { input: '1 2\n', expected_output: '3\n' },
      { input: '5\n7\n', expected_output: '12\n', hidden: true, weight: 2 }
    ],
    scoring: 'weighted'
  })
});
const result = await res.json();
console.log(result.verdict, result.score, result.passed + '/' + result.total);

Questions

Does each test count as a run?
Yes. A request with 10 tests uses 10 runs of your monthly allowance and 10 of your per-minute and pending limits. Tests that never started, such as those skipped after a compile error, are not counted.
How many tests can one request hold?
Up to your plan's pending limit: 32 on Free, 60 on Starter, 120 on Pro, 240 on Business, 600 on Platform. They must also fit the request's 60-second budget, so a long time_limit or a slow-compiling language fits fewer; the table above shows the most at the default time limit.
Can I send a whole class at once?
Yes, with async: true. Each submission waits in your account's queue, and up to 320 on Free, 600 on Starter, 1,200 on Pro, 2,400 on Business, 6,000 on Platform can wait at a time, holding at most 64 MB of requests. They are judged one at a time in the order sent, each starting as your per-minute and pending limits have room, so a burst waits instead of getting 429.
Can I run the same request twice by accident?
Not if you send an Idempotency-Key. A retry of the same request with the same key, within 24 hours, answers with the original result and runs nothing.
Can students see the hidden tests?
No. A hidden test returns only its verdict: no output, error, time or memory. compile_error is filled in only when at least one test is visible.
Can each test pass arguments or have a lower memory limit?
Yes. Give a test args, a list of up to 32 strings the program receives after its command (not for sqlite-3, duckdb-1.5 or erlang-29). memory_limit, from 16 to 2048 MB, applies to every test of the request (above 512, on Pro and above or with an exam tier, it raises the sandbox's cap); a test whose program peaks above it is memory_limit_exceeded. The peak includes the language's runtime, so leave headroom.
How is the output compared?
trim, the default, strips trailing whitespace from each line and trailing blank lines, then compares exactly. exact compares byte for byte, tokens ignores all spacing and line breaks, float accepts numbers within a tolerance, and rows ignores the order of the lines as well, for SQL and pandas answers. table and table_ordered read both outputs as CSV tables with a header row and compare them by column name, with missing values and numbers compared loosely, rows in any order or in order.
Can a test suite use a PostgreSQL database?
Yes, on Pro and above and the exam tiers. Add "services": ["postgresql"] to the suite on python-3.14-tests or nodejs-24-tests and send memory_limit of at least 1024 MB: a fresh PostgreSQL 18.6 server starts in the same sandbox before the tests, runs your .sql files under db/ in name order, and sets DATABASE_URL. It allows 8 connections, keeps its data in memory and is gone when the run ends, and the whole suite is still one run. Students' SQL queries can be graded this way too, run as a role that can only read.
How do I grade a pandas or SQL question?
Put the data in files, send it with the request, and have the program print its answer, one row per line. Use the rows checker so the order of the rows does not matter and a float column only has to match within tolerance, or print the DataFrame with print(df.to_csv(index=False)) and use table, which also checks the column names. python-3.14 has pandas 3 and python-3.14-pandas2 has pandas 2; duckdb-1.5 runs SQL and reads the files with read_csv. Heavy imports take time, so raise time_limit: pandas takes about 0.55 s to import and scikit-learn about 1.5 s.