This API is used to execute code snippets in different languages. Given below are the details of this API
This route takes 4 fields:
-
langauge
: The language of the code snippet.Click to see supported languages
- python
- rust
- cpp
- c
- java
-
code
: The code snippet to be executed. -
timeout
: The maximum time in seconds for which the code should run. If the code runs for more than this time, it will be terminated.- default: 5 seconds
- max: 60 seconds
-
max_memory
: The maximum memory in KB (kilobytes) that the code can use. If the code uses more memory than this, it will be terminated.- default: 32768KB (or 32MB)
- max: 131072KB (or 128MB)
{
"language": "python",
"code": "print('Hello World')"
}
Click to copy curl command
curl --location 'https://codeapi.anga.codes/execute' \
--header 'Content-Type: application/json' \
--data '{
"language": "python",
"code": "print('\''Hello World'\'')"
}'
{
"output": "Hello World\n", // Output of the code
"error": "", // If any error occurs during execution
"memory_used": "13808 KB", // RAM used (in KB)
"cpu_time": "125.034027ms" // in Seconds
}
{
"language": "python",
"code": "import time\nprint('Hello World')\ntime.sleep(5)",
"timeout": 2, // in seconds (defaults to 5, max 60)
}
Click to copy curl command
curl --location 'https://codeapi.anga.codes/execute' \
--header 'Content-Type: application/json' \
--data '{
"language": "python",
"code": "import time\nprint('\''Hello World'\'')\ntime.sleep(5)",
"timeout": 2
}'
{
"output": "", // No output is returned on timeout
"error": "Execution Timed Out", // Error message in case of timeout
"memory_used": "15856 KB", // RAM used (in KB)
"cpu_time": "2.000637132s" // Time before code was terminated
}
{
"language": "python",
"code": "import random;[random.random() for x in range(10**7)]",
"max_memory": 300000 // in KB (defaults to 32768, max 131072)
}
Click to copy curl command
curl --location 'https://codeapi.anga.codes/execute' \
--header 'Content-Type: application/json' \
--data '{
"language": "python",
"code": "import random;[random.random() for x in range(10**7)]",
"max_memory": 300000
}'
{
"output": "",
"error": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n File \"<string>\", line 1, in <listcomp>\nMemoryError\n",
"memory_used": "283964 KB",
"cpu_time": "803.820445ms"
}
{
"language": "python",
"code": "a = input()\nprint(f'first value entered is {a}.')\nb=input()\nprint(f'second value entered is {b}.')",
"inputs": [
"bob",
"alice"
]
}
Click to copy curl command
curl --location 'https://codeapi.anga.codes/execute' \
--header 'Content-Type: application/json' \
--data '{
"language": "python",
"code": "a = input()\nprint(f'\''first value entered is {a}.'\'')\nb=input()\nprint(f'\''second value entered is {b}.'\'')",
"inputs": [
"bob",
"alice"
]
}'
{
"output": "first value entered is bob.\nsecond value entered is alice.\n",
"error": "",
"memory_used": "13400 KB",
"cpu_time": "135.266682ms"
}