Run code: get a program's output, errors and exit code
POST source code, a compiler id and optional input. /api/run-code-sync/ waits for the run and returns its output, errors, exit code, run time and memory in the response; /api/run-code/ answers at once and POSTs the same result to the callback URL on your API key.
Try it without an API key
Edit the program or its input and press Run. It runs for real, and below you get the request your code would send and the response it would get back.
name = input()
print(f"Hello, {name}!") World
The request
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "python-3.14",
"code": "name = input()\nprint(f\"Hello, {name}!\")",
"input": "World"
}'The response
Press Run in the editor to see it.
To send it from your own code, get a free API key: 100,000 runs a month, no credit card.
Run Code (Sync)
NewExecute code and get results in a single request. No callback URL needed: the response contains the execution output directly. Ideal for simple integrations, scripts, and AI agents.
/api/run-code-sync/Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
| compiler | string | Yes | Compiler identifier (see list below) |
| code | string | Yes | Source code to execute (max 100KB) |
| input | string | No | Standard input for the program (max 5 MB) |
| time_limit | number | No | Seconds the program may run, above 0 and up to 30. The run is stopped at this limit with exit code 124; compiling before it does not count, but Java, Groovy and F# get a start-up allowance on top. Without it, the run gets what is left of the 30-second timeout. |
| files | array | No | Files for the program (data or helper source, see several source files), each {name, content, encoding}: up to 20 files and 1 MB in total. See files in and out. |
| args | array | No | Command-line arguments for the program, up to 32 strings and 4,096 bytes in all. Not for sqlite-3, duckdb-1.5 or erlang-29. See arguments and a memory limit. |
| memory_limit | integer | No | MB the program may use at its peak, 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 run over it reports exit code 137. Without it, the sandbox's 512 MB applies. |
Response (200)
{
"output": "Hello, World!\n",
"error": "",
"status": "success",
"exit_code": 0,
"signal": null,
"truncated": false,
"time": "0.0248",
"total": "0.0330",
"memory": "8192",
"time_limit": 30,
"memory_limit": 512
}Calling this from a web page? The API sends no CORS headers and a key in browser code is public, so call it from a route on your own server. How to build an online code editor in React shows the server route and the Run button.
Examples
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "python-3.14",
"code": "name = input()\nprint(f\"Hello, {name}!\")",
"input": "World"
}'Run Code (Async)
/api/run-code/Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
| compiler | string | Yes | Compiler identifier (see list below) |
| code | string | Yes | Source code to execute (max 100KB) |
| input | string | No | Standard input for the program (max 5 MB) |
| time_limit | number | No | Seconds the program may run, above 0 and up to 30. The run is stopped at this limit with exit code 124; compiling before it does not count, but Java, Groovy and F# get a start-up allowance on top. Without it, the run gets what is left of the 30-second timeout. |
| files | array | No | Files for the program (data or helper source, see several source files), each {name, content, encoding}: up to 20 files and 1 MB in total. See files in and out. |
| args | array | No | Command-line arguments for the program, up to 32 strings and 4,096 bytes in all. Not for sqlite-3, duckdb-1.5 or erlang-29. See arguments and a memory limit. |
| memory_limit | integer | No | MB the program may use at its peak, 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 run over it reports exit code 137. Without it, the sandbox's 512 MB applies. |
| extra_params | object | No | JSON object returned in the callback (max 8KB) |
202 Accepted immediately with a queue ID.
Results are delivered to your API key's redirect URL as a POST callback. Use a public HTTP(S) URL; private addresses, embedded credentials, and HTTP redirects are not supported.
The callback body doesn't repeat the queue ID, so put your own reference in extra_params to match each result to its request.
If the queue can't take the run, the request answers 503 with {"error": "Execution queue unavailable"} (or "Could not store input files"); try again shortly.Code Examples
curl -X POST https://api.onlinecompiler.io/api/run-code/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "python-3.14",
"code": "name = input()\nprint(f\"Hello, {name}!\")",
"input": "World"
}'The official clients send these requests for you: client.run({ compiler, code, input }) in Node.js (npm install onlinecompiler) and client.run(compiler, code, input=...) in Python (pip install onlinecompiler), with submit for the async endpoint. See the Node.js client and Python client.
Response
Immediate Response (202)
{ "status": "queued", "id": 42 }Callback POST Body
Once execution completes, results are POSTed to your API key's redirect URL:
{
"output": "Hello, World!\n",
"error": "",
"status": "success",
"exit_code": 0,
"signal": null,
"truncated": false,
"time": "0.0248",
"total": "0.0330",
"memory": "8192",
"time_limit": 30,
"memory_limit": 512,
"extra_params": {}
}| Field | Description |
|---|---|
| output | Standard output (up to 64 KB; NUL and invalid UTF-8 bytes come back as U+FFFD) |
| error | Standard error / compilation errors (up to 64 KB; NUL and invalid UTF-8 bytes come back as U+FFFD) |
| status | "success" or "error" |
| exit_code | Process exit code (0 = success) |
| signal | Signal number if killed (e.g. 9 for SIGKILL), null otherwise |
| truncated | true if output or error went over 64 KB and was cut |
| time | Run-command wall time in seconds; includes the compilation Java, F#, Deno, Dart, Erlang, Elixir, Clojure, Groovy and Racket do as they run |
| total | Script wall time in seconds, including separate compilation; excludes container startup |
| memory | Memory usage in KB |
| files | Files the program wrote to $OUTPUT_DIR, each {name, mime, size, content_base64, url}; an empty list when there are none. url is null when the file was not stored. See files in and out |
| files_truncated | true if the program wrote more than 8 files or 2 MB, or files of a type that is not returned, and some were left out |
| time_limit | The run's time limit in seconds: yours, or 30 without one |
| memory_limit | The run's memory limit in MB: yours, or 512 without one |
| extra_params | Your custom data, passed through unchanged |
Exit Codes & Signals
The exit_code field contains the process exit code. A value of 0 means the program ran successfully. Any non-zero value indicates an error.
When exit_code is greater than 128, the process was killed by a signal. The signal field provides the signal number (i.e. exit_code - 128). When the process exits normally, signal is null.
| Exit Code | Signal | Meaning |
|---|---|---|
| 0 | null | Success |
| 1 | null | Runtime error (e.g. uncaught exception, assertion failure) |
| 2 | null | Misuse of command / invalid arguments |
| 137 | 9 (SIGKILL) | Killed: over the 512 MB memory limit, or over your memory_limit, when error ends with how much it used (memory limit) |
| 139 | 11 (SIGSEGV) | Segmentation fault: invalid memory access |
| 124 | null | Timeout: the run went over your time_limit (plus the start-up allowance for Java, Groovy and F#), or compile and run together went over 30 seconds |
| 153 | 25 (SIGXFSZ) | Stopped for flooding output: more than 8 MB across both streams |
| 71 | null | Too many processes: more than your plan allows running at once (16 on Free and Starter, 100 on Pro and Business, 200 on Platform), so the sandbox stopped. Output printed before that is kept, and error says what happened |
Arguments and a memory limit
Both endpoints take args and memory_limit. Run-tests takes args on each test and one memory_limit for every test, and the Judge0, Piston and Jobe endpoints pass their own arguments field on as args and ignore their memory limits.
Command-line arguments
argsis a list of strings that the program receives after its own command, in order and exactly as sent: no shell splits, expands or quotes them, so"two words"arrives as one argument.- Up to 32 strings and 4,096 bytes in all, as UTF-8, with no NUL characters. Missing,
nulland[]all mean none. - sqlite-3, duckdb-1.5 and erlang-29 cannot take arguments: SQLite and DuckDB read the program on stdin, and the Erlang launcher starts
mainwith none. A request with arguments for one of them answers 400, such as{"error": "args are not supported for sqlite-3"}. - The WebSocket's
runcodeevent does not pass them on; itsruntestsevent does, per test.
Memory limit
memory_limitis a whole number of MB from 16 to 2048 (2 GB), sent as an integer (64.0is refused). Without it a run gets 512 MB.GET /api/limits/hasmin_memory_mb, the defaultmemory_mbandmax_memory_mb.- Above 512 MB it raises the sandbox's own memory cap for that run, on Pro and above, and on any plan with a CodeRunner exam tier; the run still counts as one run. On Free and Starter a value above 512 is refused with status 400 and a link to the plan that allows it.
GET /api/usage/gives your account's ceiling asmax_memory_mb. The cap is a ceiling, not a reservation: a program uses only what it needs. A program that goes past it is stopped and reported as a memory kill (exit_code137,signal9). Java, Kotlin, .NET and the duckdb Python package size their memory from the cap, so under a higher one they may use more memory than they would at 512 MB. - At or below 512 MB, it is checked against the program's peak memory, the figure the result reports as
memory, once the program ends. The sandbox itself keeps 512 MB, so the program is not stopped when it passes your limit; a run over it is reported as a memory kill:exit_code137,signal9, and a line at the end oferrorsaying how much it used. What it printed is kept. A run that also went over its time limit reports 124. - The peak is that of the run command, as for
time: a separate compile step never counts, but the language's runtime does, and so do the library files the program maps. A program that only prints hello uses about 15 MB in Python (65 MB once it imports numpy), 60 MB in C#, 210 MB in Kotlin and Scala, 230 MB in Java and Clojure, 270 MB in Groovy, 350 MB in F# and 390 MB in Julia, so setmemory_limitwell above the figure for your language, plus what the program's own data needs. Importing the whole Python data stack reports about 430 MB, so data science programs need a high limit or none. - The result's
memory_limitis the limit the run had: yours, or 512 without one. - The WebSocket's
runcodeevent does not apply it; itsruntestsevent does.
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "python-3.14",
"code": "import sys\nprint(sys.argv[1:])",
"args": ["--size", "10", "two words"],
"memory_limit": 64
}'{
"output": "['--size', '10', 'two words']\n",
"exit_code": 0,
"memory_limit": 64,
"...": "the other fields as above"
}{
"output": "",
"error": "Memory limit exceeded: the program used 81 MB, over the memory_limit of 64 MB.\n",
"status": "error",
"exit_code": 137,
"signal": 9,
"memory": "82144",
"memory_limit": 64,
"...": "the other fields as above"
}Files in and out
Send small input files with a run, such as a CSV, and get back the files the program writes, such as a chart. Both work on the sync and async endpoints, in every language, and on run-tests. They cost nothing extra: a run is a run on every plan.
Input files
filesis a list of{"name": "data.csv", "content": "...", "encoding": "utf8"}.encodingisutf8(the default) orbase64for binary files such as an Excel workbook.- At most 20 files and 1 MB in total after decoding. A bad file answers 400 with a message and nothing runs. A marketplace that fronts the API, such as RapidAPI, may apply a smaller body limit of its own.
- A name is letters, digits, dots, dashes and underscores, starting with a letter or digit, up to 100 characters a part. It may have folders: up to 4 parts joined by
/, 200 characters in all, with no.., no leading slash and no empty part. Names must differ, and a name can't also be the folder of another. The first part can't beinput,run.sh,build,build.tarorgo-trim.txt, and the part before its first dot can't becode, which is the program's own file name. - The program finds the files in its working directory (see several source files for helper code), so
pd.read_csv("sales.csv")works as written. SQL runs read them withread_csv('sales.csv')in DuckDB. - On the async endpoint, files wait with the job until it runs, and are deleted when its result is final.
Several source files
A program can have more than one source file. Send the helpers in files next to the program, which stays in code and is the entry point. A name may carry folders, such as pkg/util.py: up to 4 parts and 200 characters, each part made of letters, digits, dots, hyphens and underscores. The limits are the ones above: 20 files and 1 MB in total. It works on run-code, run-tests, the WebSocket and the MCP tools.
- A compiled language builds the other files of its own language (by extension) together with the program; the table gives each language's exact rule. A file your program includes, such as
#include "util.c"or COBOL'sCOPY util., is compiled as part of the program, not again on its own. A file with that extension is compiled even if you meant it as data, so give data another extension. Extensions:.cfor C;.cc .cpp .cxxfor C++;.mfor Objective-C;.java;.go;.cs;.vb;.kt;.scala;.swift;.ml .mli;.f90 .f95 .f03 .f08;.cob .cbl;.bas;.d;.erl;.ex. - An interpreted language, and the compiled ones that follow imports (Rust, Haskell, Pascal, Ada, Nim, Zig, Crystal, Dart), load a helper the way the language does. The table lists how.
- With no extra files, a run behaves as it always did.
- With run-tests, the files reach the compile step too, so a header and its
.cfile work in every test. - A C++ class in
Student.handStudent.cpp, step by step, in both the header and the#include "Student.cpp"style, with the errors each mistake gives: header files in an online C++ compiler.
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "gcc-15",
"code": "#include <stdio.h>\n#include \"util.h\"\nint main(void) { printf(\"%d\\n\", add(2, 3)); return 0; }",
"files": [
{"name": "util.h", "content": "int add(int a, int b);\n"},
{"name": "util.c", "content": "#include \"util.h\"\nint add(int a, int b) { return a + b; }\n"}
]
}'| Language | How a helper file is used |
|---|---|
| python-3.14, python-3.14-pandas2 | import util; with a folder, from pkg import util (pkg/util.py, no __init__.py needed) |
| nodejs-24 | require('./util') or require('./lib/util') |
| typescript-deno | import { add } from "./util.ts" (the extension is required) |
| php-8.5 | require 'util.php'; |
| ruby-4.0 | require_relative 'util' |
| perl-5.44 | require "./util.pl"; (the file ends with 1;) |
| lua-5.5 | require "util" |
| r-4.6 | source("util.R") |
| julia-1.13 | include("util.jl") |
| octave-11 | a function file named after its function (add2.m defines add2), called by name |
| bash-5.2 | source util.sh |
| powershell-7.6 | . ./util.ps1 |
| racket-9.3 | (require "util.rkt"); the helper starts with #lang racket and has a (provide ...) |
| sbcl-2.6 | (load "util.lisp") |
| swipl-10 | :- consult(util). |
| clojure-1.12 | (load-file "util.clj") |
| groovy-6.0 | not found by class name. Load it explicitly: evaluate(new File("Util.groovy")), or this.class.classLoader.parseClass(new File("Util.groovy")) |
| dotnet-fsharp-10 | #load "util.fsx" (the helper declares module Util) |
| rust-1.93 | mod util; with util.rs; a nested mod a; with a/mod.rs |
| haskell-9.12 | import Util with Util.hs (module Util where) |
| fpc-3.2 | uses util; with util.pas, a unit |
| gnat-15 | with Util; with util.ads and util.adb |
| nim-2.2 | import util with util.nim (export with *) |
| zig-0.17 | @import("util.zig") |
| crystal-1.22 | require "./util" |
| dart-3.13 | import 'util.dart'; |
| nasm-3 | %include "util.asm" (a textual include, one object) |
| sqlite-3, duckdb-1.5 | .read util.sql |
| gcc-15 | every other .c file is compiled and linked with the program, unless a file includes it; headers are found by #include, in folders too |
| g++-15, g++-15-cpp20 | every other .cc, .cpp and .cxx file is compiled and linked, unless a file includes it; headers as in C |
| clang-objc-21 | every other .m file is compiled and linked, unless a file includes or imports it |
| openjdk-25 | other classes are found by their package folders (com/acme/Util.java for package com.acme) or by file name |
| go-1.26 | with a go.mod, the module is built (a package in a folder is imported as module/dir); without one, the top-level .go files are compiled with the program |
| dotnet-csharp-10 | every other .cs file, in folders too, is compiled with the program; one Main in all |
| dotnet-vbnet-10 | every other .vb file is compiled with the program |
| kotlin-2.4 | every other .kt file is compiled with the program |
| scala-3.10 | every other .scala file is compiled with the program |
| swift-6.4 | every other .swift file is compiled; the program is compiled as main.swift when helpers exist, so diagnostics name main.swift; only the program file may hold top-level code; a sent main.swift is ignored |
| ocaml-5.4 | top-level .ml and .mli files only (folders are not searched), compiled in dependency order |
| gfortran-15 | every other .f90, .f95, .f03 and .f08 file is compiled first, in name order, so a module another helper uses must sort before it; a file brought in with include 'util.f90' is not compiled on its own |
| gnucobol-3.2 | every other .cob and .cbl file is linked and reached by a static CALL; code is the main program; .cpy files are found by COPY, and a .cob or .cbl file brought in by COPY (COPY util. finds util.cbl) is not compiled on its own |
| fbc-1.10 | every other .bas file is compiled with the program, unless a file includes it with #include |
| ldc-1.43 | other .d files are compiled when the program imports them; module names match the paths |
| erlang-29 | each other .erl file is compiled before the run; its module cannot be named code |
| elixir-1.20 | every .ex file is required before the program script |
Output files
- Every run has an empty directory at
/tmp/outputs, and the environment variableOUTPUT_DIRholds its path, in every language. Write files there and they come back infiles. - In Python,
plt.show()saves each open figure asfigure-1.png,figure-2.pngand so on, so tutorial code returns its charts unchanged. Each figure comes back once, in order.plt.savefigto a path under$OUTPUT_DIRworks too. - Types that come back: png, svg, csv, json, txt, checked against their content (a
.pngthat is not a PNG is dropped). Folders, links and files whose names hold control or invisible formatting characters are skipped. Files of other types, or whose names start with a dot, are left out without using up one of the 8 places. - At most 8 files and 2 MB per run. Anything over is left out and
files_truncatedis true; the run itself still succeeds. File bytes don't count against the 8 MB output flood limit or the 64 KB output cap, and writing them doesn't count toward the run's time. content_base64holds the bytes in the response, so you don't need the URL.urlis where the account that ran it can fetch the file again for 60 days:GET /api/files/<id>/with any of that account's API keys in theAuthorizationheader. Other accounts get 404, and so does anyone after 60 days.- An account stores up to 1 GB. Past that, files still come back in the response, but
urlis null. It is also always null in run-tests results, in widget and WebSocket runs (widget keys can't call the REST API), in calls through RapidAPI, and while the server is short of disk space. The file is still incontent_base64. - The Judge0 and Piston responses have no field for files, so they never return output files.
Example: a CSV in, a chart out
import base64
import requests
code = """
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("sales.csv")
totals = df.groupby("region")["amount"].sum()
print(totals)
totals.plot.bar()
plt.show()
"""
response = requests.post(
"https://api.onlinecompiler.io/api/run-code-sync/",
headers={"Authorization": "YOUR_API_KEY"},
json={
"compiler": "python-3.14",
"code": code,
"files": [
{"name": "sales.csv", "content": "region,amount\nnorth,10\nsouth,20\nnorth,5\n"}
],
},
)
result = response.json()
print(result["output"])
for f in result["files"]:
with open(f["name"], "wb") as out:
out.write(base64.b64decode(f["content_base64"])){
"output": "region\nnorth 15\nsouth 20\nName: amount, dtype: int64\n",
"error": "",
"status": "success",
"exit_code": 0,
"files": [
{
"name": "figure-1.png",
"mime": "image/png",
"size": 18734,
"content_base64": "iVBORw0KGgo...",
"url": "https://api.onlinecompiler.io/api/files/123/"
}
],
"files_truncated": false
}import os
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [2, 4, 8])
plt.savefig(os.path.join(os.environ["OUTPUT_DIR"], "growth.png"))Python data science
python-3.14 comes with NumPy, pandas 3, SciPy, scikit-learn, Matplotlib, seaborn, statsmodels, SymPy, openpyxl, Pillow and DuckDB. python-3.14-pandas2 has the same packages at their late-2025 versions, with pandas 2. The versions are in the package table, with import times, memory and how to use DuckDB from Python.
memory field counts the library files Python maps, so a hello world that imports the whole stack reports about 430 MB while really using about 200 MB. Your data and models have the rest of the 512 MB.Questions
- Should I use the sync or the async endpoint?
- Use /api/run-code-sync/ when you can wait for the result in the same request: it returns when the run ends, within 30 seconds, and answers 429 when your account's runs at once are all busy. Use /api/run-code/ to queue runs: it answers 202 at once, waits for a free sandbox and POSTs each result to your callback URL.
- How do I send input to the program?
- Send it as input, up to 5 MB: the program reads it as standard input. SQL is the exception, because SQLite and DuckDB read the program from standard input; there the script reads input with readfile('input') in SQLite and read_text('input') in DuckDB.
- What do exit codes 124, 137, 153 and 71 mean?
- 124: the run went over its time_limit, or compiling and running together went over 30 seconds. 137 (signal 9): the program went over its memory limit: the sandbox's 512 MB, or the memory_limit you sent (a lower one ends error with a line saying how much it used). 153 (signal 25): it printed more than 8 MB. 71: it had more than 16 processes running at once, so the sandbox stopped; error says so. Other codes come from the program itself, such as 1 for an uncaught Python exception.
- Can I pass command-line arguments or set a lower memory limit?
- Yes. args is a list of up to 32 strings (4,096 bytes in all) that the program receives after its own command, exactly as sent; sqlite-3, duckdb-1.5 and erlang-29 cannot take them. memory_limit, a whole number of MB from 16 to 2048, sets the run's memory: above 512, on Pro and above or with an exam tier, it raises the sandbox's cap, and below it is checked against the program's peak memory; a run over it reports exit code 137, as a memory kill does.
- Can a program return a chart or other files?
- Yes. Write files to $OUTPUT_DIR (/tmp/outputs) and they come back in the files field of the result, up to 8 files and 2 MB: png, svg, csv, json, txt. In Python, plt.show() saves each figure as figure-1.png, figure-2.png and so on; in Octave, the figures still open when the program ends are saved the same way. Each file is in the response as base64, and its url, when it has one, works for 60 days with your API key.
- How do I give the program a data file?
- Send files: [{name, content, encoding}] with the run: up to 20 files and 1 MB in total, utf8 or base64. The program finds them in its working directory, so pd.read_csv("data.csv") works.