Documentation
Everything you need to integrate code execution into your application. One endpoint, 12 languages, real-time results.
https://api.onlinecompiler.ioAuthentication
All API requests require an API key passed in the Authorization header.
Key Types
There are two types of API keys, each scoped to specific endpoints:
| Key Type | Created From | Allowed Endpoints | Use Case |
|---|---|---|---|
| API | API Keys page | REST API (sync & async) | Server-side integrations, scripts, AI agents |
| WebSocket | Widgets page | WebSocket & embeddable widget | Embedded editors, browser-based apps |
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 100KB) |
| extra_params | object | No | Custom JSON data returned in the callback |
202 Accepted immediately with a queue ID.
Results are delivered to your API key's redirect URL as a POST callback.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 100KB) |
Response (200)
{
"output": "Hello, World!\n",
"error": "",
"status": "success",
"exit_code": 0,
"signal": null,
"time": "0.0248",
"total": "0.0330",
"memory": "8192"
}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"
}'Supported Compilers
python-3.14gcc-15g++-15openjdk-25dotnet-csharp-9dotnet-fsharp-9php-8.5ruby-4.0haskell-9.12go-1.26rust-1.93typescript-deno/api/compilers/Fetch this list programmatically. No authentication required.
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,
"time": "0.0248",
"total": "0.0330",
"memory": "8192",
"extra_params": {}
}| Field | Description |
|---|---|
| output | Standard output (max 999 chars) |
| error | Standard error / compilation errors (max 999 chars) |
| status | "success" or "error" |
| exit_code | Process exit code (0 = success) |
| signal | Signal number if killed (e.g. 9 for SIGKILL), null otherwise |
| time | Execution time in seconds (excludes compilation) |
| total | Total time in seconds (includes compilation) |
| memory | Memory usage in KB |
| 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 — memory limit exceeded or timeout |
| 139 | 11 (SIGSEGV) | Segmentation fault — invalid memory access |
| 124 | null | Timeout — execution exceeded the 30-second limit |
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"
}'WebSocket (Real-time)
For real-time results without polling, connect via Socket.IO. The WebSocket server authenticates your API key, forwards code to the execution engine, and pushes results back instantly.
WebSocket URL
wss://api.onlinecompiler.ioEmit Event
runcodeListen Event
codeoutputimport { io } from "socket.io-client";
const socket = io("wss://api.onlinecompiler.io", {
auth: { token: "YOUR_API_KEY" }
});
socket.on("connect", () => {
socket.emit("runcode", {
api_key: "YOUR_API_KEY",
compiler: "python-3.14",
code: 'print("Hello via WebSocket!")',
input: ""
});
});
socket.on("codeoutput", (result) => {
console.log(result.output); // "Hello via WebSocket!"
console.log(result.error); // ""
console.log(result.status); // "success"
console.log(result.exit_code); // 0
console.log(result.signal); // null
console.log(result.time); // "0.0248"
console.log(result.total); // "0.0330"
console.log(result.memory); // "8192"
});Embeddable Widget
Drop a fully-featured code editor into any webpage with a single script tag. The widget includes a CodeMirror 6 editor with syntax highlighting, language selector, stdin input, and real-time execution via WebSocket. It uses Shadow DOM for complete style isolation.
Quick Start
<!-- 1. Add the widget script (before </body>) -->
<script src="https://onlinecompiler.io/widget.js"></script>
<!-- 2. Add a div with your API key -->
<div class="runcode"
data-key="YOUR_API_KEY"
data-lang="python-3.14">
</div>Configuration
Configure each widget instance using data-* attributes:
| Attribute | Required | Default | Description |
|---|---|---|---|
| data-key | Yes | - | Your API key |
| data-lang | No | python-3.14 | Default language (any compiler key) |
| data-theme | No | dark | dark or light |
| data-height | No | 400 | Editor height in pixels |
Multiple Widgets
Add as many widgets as you need. Use class="runcode" for multiple widgets or id="runcode" for a single one. Each widget operates independently with its own editor, language, and connection.
<!-- Dark theme, 400px height -->
<div class="runcode"
data-key="YOUR_API_KEY"
data-lang="python-3.14"
data-theme="dark"
data-height="400">
</div>
<!-- Light theme, 300px height, Java -->
<div class="runcode"
data-key="YOUR_API_KEY"
data-lang="openjdk-25"
data-theme="light"
data-height="300">
</div>
<!-- Multiple widgets on the same page work independently -->
<script src="https://onlinecompiler.io/widget.js"></script>MCP (AI Agents)
NewConnect AI assistants like Claude, Cursor, VS Code Copilot, and any MCP-compatible client directly to OnlineCompiler.io. No SDK to install — just add a URL.
https://api.onlinecompiler.io/mcpThe server exposes two tools: list_compilers and run_code. Authentication uses your API key as a Bearer token.
Claude Code
claude mcp add onlinecompiler https://api.onlinecompiler.io/mcp --transport http --header "Authorization: Bearer YOUR_API_KEY"VS Code / Cursor
Add to .vscode/mcp.json or .cursor/mcp.json:
{
"servers": {
"onlinecompiler": {
"url": "https://api.onlinecompiler.io/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"onlinecompiler": {
"url": "https://api.onlinecompiler.io/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}Limits & Constraints
| Memory | 512 MB per execution |
| CPU | 2 cores |
| Timeout | 30 seconds |
| Max Processes | 64 PIDs |
| Network | Disabled (no outbound access) |
| Code Size | 100 KB max |
| Input Size | 100 KB max |
| Output | Truncated at 999 characters |
| Sync Concurrency | 4 concurrent requests max (returns 429 when at capacity) |
| WebSocket Rate | 1 execution per second per connection |