This repository contains a remote code execution engine that allows users to submit code in various programming languages, execute it in isolated Docker containers, and retrieve the output. The engine supports both x86_64
and arm64
architectures.
- Supports C++ and Go programming languages.
- Executes code in isolated Docker containers.
- Supports both
x86_64
andarm64
architecture machines. - Cleans up zombie containers to avoid memory leaks.
- Provides a REST API for code submission and execution.
- Restricts the usage of system resources (Memory, CPU, max processes, max files, max file size)
- Kills a container if it is taking more than a minute to complete the execution.
- Supports custom docker images and compilation commands for each programming language.
- Docker
- Go
-
Clone the repository:
git clone https://github.com/srujangit123/Remote-Code-Execution-Engine.git cd Remote-Code-Execution-Engine
-
Build the Docker images: This builds the default docker images and uses the default config (
config.yml
) Skip this step if you want to use custom docker images and commands. Make sure you modify theconfig.yml
if you are using custom docker images and commandsbash scripts/build_docker.sh
-
Build the server:
go build -o server cmd/server.go
The configuration file config.yml specifies the settings for each supported language. Here is an example configuration:
cpp:
extension: ".cpp"
image: "cpp_arm64:latest"
command: "/usr/bin/run-code.sh {{LANGUAGE}} {{FILE}} {{INPUT}}"
golang:
extension: ".go"
image: "golang_arm64:latest"
command: "/usr/bin/run-code.sh {{LANGUAGE}} {{FILE}} {{INPUT}}"
- {{LANGUAGE}} - programming language
- {{FILE}} - Code file with the extension as specified in the config
- {{INPUT}} - Input file if the input is provided by the user
These variables are replaced with appropriate values before creating the code container.
To start the server, run the following command:
./server
--code-dir
The default directory where the code files will be stored is/tmp/
A separate directory is created for every language. To change the directory where the code files will be stored(eventually removed by the garbage collector), use
./server --code-dir /path/to/code/dir
--resource-constraints
By default, resource constraints are turned off to improve the performance, if you want to enable it, use
./server --resource-constraints true
- URL:
/api/v1/languages
- Method:
GET
- URL:
/api/v1/submit
- Method:
POST
- Content-Type:
application/json
- Request Body:
{
"code": "base64_encoded_code",
"input": "base64_encoded_input",
"language": "cpp"
}
- Response:
{
"output": "execution_output"
}
To submit a code execution request, you can use the following curl
command:
curl -X POST http://localhost:9000/api/v1/submit \
-H "Content-Type: application/json" \
-d '{"code": "base64_encoded_code", "input": "base64_encoded_input", "language": "cpp"}'