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.

POST
uapis.cn
/api/v1/execution/run
Body
language
string
required

Programming language and its recommended identifier.

code
string
required

The full source code. Max 65536 bytes.

stdin
string

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

timeout_ms
integer

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

network
object

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

mode
string

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

allow_hosts
array[string]

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

Supports multiple values separated by commas
allow_ports
array[integer]

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

Supports multiple values separated by commas
packs
array[string]
Third-party library packs to load. Available values: python-libs, node-libs (shared by JavaScript/TypeScript), go-libs, c-libs, cpp-libs. See the for what each pack includes. Pass an empty array [] or omit when not needed.
Supports multiple values separated by commas

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. You can also use internal mode for unrestricted network access.

Third-party library packs Use the packs parameter to load popular third-party libraries for your code (such as requests for Python or axios for Node) — ready to use, no installation needed.

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).

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; internal: unrestricted 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
Third-party library packs to load. Available values: python-libs, node-libs (shared by JavaScript/TypeScript), go-libs, c-libs, cpp-libs. See the for what each pack includes. Pass an empty array [] or omit when not needed.

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
{
  // Final status of the user program.
  "status": "success",
  // The language actually used by the execution environment.
  "language": "python",
  // Standard output of the program.
  "stdout": "Hello, UapiPro!\n",
  // Standard error or compiler diagnostics.
  "stderr": "",
  // Process exit code. Returns null if the process produced no normal exit code.
  "exit_code": 0,
  // Signal number that terminated the process (null if not signal-terminated).
  "signal": 123,
  // Compilation time in milliseconds. Usually 0 for interpreted languages.
  "compile_ms": 0,
  // Actual runtime of the user program in milliseconds.
  "run_ms": 20,
  // Total internal scheduling time of the execution environment in milliseconds.
  "total_ms": 20,
  // Whether the execution cache was hit (currently always false).
  "cached": false,
  // Whether the run was terminated for exceeding timeout_ms.
  "timed_out": false,
  // Whether stdout was truncated for exceeding limits.
  "stdout_truncated": false,
  // Whether stderr was truncated for exceeding limits.
  "stderr_truncated": false,
  // Security policy description of the execution environment, mainly for diagnostics.
  "security_mode": "string",
  // Short environment-level error reason. Null when no extra error occurred.
  "error": "string"
}

400 / Bad Request

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

JSON
{
  "code": "INVALID_PARAMETER",
  "message": "timeout_ms must be between 1 and 30000"
}

413 /

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

JSON
{
  "code": "SOURCE_TOO_LARGE",
  "message": "Source code exceeds the maximum allowed byte limit"
}

503 / Service Unavailable

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

JSON
{
  "code": "EXECUTION_UNAVAILABLE",
  "message": "Code execution service is temporarily unavailable"
}

504 / Gateway Timeout

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

JSON
{
  "code": "EXECUTION_TIMEOUT",
  "message": "Timed out waiting for execution result"
}