Skip to content

bilginyuksel/remote-code-execution

Repository files navigation

Remote Code Execution

Run the application codes for multiple languages using very simple APIs.

Remote code execution application creates a container then executes the code gives the response to client. Current architecture does not use DIND(Docker in Docker). The containers share the same docker daemon.

Remote Code Execution Architecture

Test the application

curl --location --request POST 'http://localhost:8888/v2/codexec' \
--header 'Content-Type: application/json' \
--data-raw '{
    "lang": "python3",
    "content": "import sys\ninp = sys.argv[1]\nfor i in range(int(inp)):\n\tprint('\''*'\'' * (i +1))",
    "args": [
        "20"
    ]
}'

Getting Started

Follow the getting started steps to run the application.

or just run make up

First change the mount source path in dev.yml and local.yml files. Source path should be pointing to the path of /target folder in your application. You can use the bash command below if you're inside the application directory with the terminal.

source_path="$(pwd)/target"
echo $source_path
mounts:
  - type: "bind"
    source: <source_path> # write the value here
    target: "/app"

Build the all-in-one-ubuntu image

docker build build/all-in-one-ubuntu -t all-in-one-ubuntu

Run the application in your local

APP_ENV=local go run . serve

Run the application using docker

Build the rce image

docker build --progress=plain -t rce -f dev.Dockerfile .

Run the container with the image you have created before.

docker run -it -p 8888:8888 -v /var/run/docker.sock:/var/run/docker.sock --mount type=bind,source=$(pwd)/target,target=/rce/target rce

Build the all-in-one-ubuntu image

Build the ubuntu docker image to run code with different languages.

docker build build/all-in-one-ubuntu -t all-in-one-ubuntu
docker run -dit all-in-one-ubuntu

Open ubuntu container from command line.

docker ps # find the container id
docker exec -it <container-id> bash

Test the compiler/interpreters.

  1. Python --> python3 --version
  2. Java --> java -version
  3. Javac --> javac -version
  4. NodeJS --> nodejs --version
  5. Golang --> /usr/local/go/bin/go version
  6. C++ --> g++ --version
  7. C --> gcc --version

Run the application (DIND)

Runs the application for unix systems

chmod +x ./scripts/up.sh && ./scripts/up.sh

Execute multiple commands with docker exec

The command below will work for ubuntu container. You need to change the bash command according to container you use. For example for alpine container it should be /bin/sh.

docker exec -w <workdir> -it <container-id> bash -c "<command> && <command>"

About

Fast remote code execution engine for multiple programming languages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published