Execution

Run code online

0calls
4 credits / call

Want to add a "run code online" feature to your programming learning site, coding practice platform, or chatbot? This endpoint gives you a secure, isolated cloud code execution environment.

Overview

Submit a piece of source code with its programming language (Python, JS, C/C++, Go, and more). The system compiles and runs it in a cloud sandbox, then returns the full standard output (stdout), standard error (stderr), execution time, and exit status.

Flexible input control Use the stdin parameter to feed the program its standard input stream — perfect for test cases on algorithm problems.

Secure, controlled network policy Code runs in a fully offline environment by default (offline mode). If user code needs to fetch external data, enable public mode and strictly limit the allowed public hosts (e.g. api.github.com) and ports, eliminating malicious network probing at the root.

Usage Notes

Important

An HTTP200 response only means the cloud service received and finished the task — it does not mean the user's code ran successfully. Always rely on the status field in the response body (success means success; other values may be compile_error, runtime_error, or timeout).

Size limits:

  • Both the source code (code) and standard input (stdin) must not exceed 65536 bytes (UTF-8 encoded).
  • The execution timeout can be set up to 30000 milliseconds (30 seconds).

About runtime packs (Packs): For now, always pass an empty array []. Do not expose this field to end users for arbitrary input, or uncontrolled dependency loading failures may occur.

Request body

Contains the programming language, source code body, and execution policy parameters. Must pass strict JSON validation.

language
stringrequired

Programming language and its recommended identifier.

code
stringrequired

The full source code. Max 65536 bytes.

stdin
stringoptional

Standard input stream passed to the program. Max 65536 bytes.

timeout_ms
integeroptional

Execution timeout of the user program in milliseconds. Range 1 - 30000.

network
objectoptional

Network access policy of the sandbox. Defaults to offline mode when omitted.

mode
stringoptional

offline: fully disconnected; public: controlled public network access.

allow_hosts
string[]optional

Hosts allowed in public mode (plain domains or IPs only). Max 16 entries.

allow_ports
integer[]optional

Target ports allowed in public mode. Defaults to 80 and 443 when omitted.

packs
string[]optional

Additional runtime packs to load. Always pass an empty array [] or omit for now.

Response

200 / OK

The cloud execution service processed the task successfully. Use the status field in the response body to determine the actual result.

JSON

400 / Bad Request

Invalid request parameters or strict JSON validation failure (e.g. unknown fields, out-of-range lengths).

JSON

413 /

Submitted content is too large. The source code (code) or input stream (stdin) may exceed the 65536-byte limit.

JSON

503 / Service Unavailable

The code execution sandbox is temporarily unavailable or the queue is full. Please retry later.

JSON

504 / Gateway Timeout

Timed out waiting for the execution result, usually due to high system load.

JSON