Skip to content

Compile and run user-submitted code in a docker based sandbox.

License

Notifications You must be signed in to change notification settings

pradeepnew/compilebox

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is it?

CompileBox is a Docker based sandbox to run untrusted code and return the output to your app. Users can submit their code in any of the supported languages. The system will test the code in an isolated environment. This way you do not have to worry about untrusted code possibly damaging your server intentionally or unintentionally. You can use this system to allow your users to compile their code right in the browser.

Check the example work at:

How does it work?

The client-side app submits the code and the languageID to the server through the API. The API then creates a new Docker container and runs the code using the compiler/interpreter of that language. The program runs inside a virtual machine with limited resources and has a time-limit for execution (20s by default). Once the output is ready it is sent back to the client-side app. The Docker container is destroyed and all the files are deleted from the server.

No two codes have access to each other’s Docker or files.

Installation Instructions

  • Go to the 'Setup' directory.

    • Open the Terminal as root user

    • Execute the script Install_*.sh, select the file which best suites your Operating System description. This will install the Docker and NodeJs pre-requisites to your system and create an image called 'virtual_machine' inside the Docker. DockerVM may take around 20 to 30 minutes depending on your internet connection.

    • Once the Install script executes successfully, copy the folder named 'API' to your desired path.

    • Open app.js in the API folder and set the variable values as follows.

      1. timeout_value: The time in seconds till which the API should wait for the output of the code before generating an "Execution Timed Out" message.
      2. port: The port on which the server will listen, the default port is 80.
    • To test the installation, open a new terminal windows, cd to the API folder and type the following command

     $ npm install .
    

    to install all needed nodejs modules, followed by

    $ sudo nodejs app.js
    
    • If everything has been setup correctly in app.js file, you will see the following message on your terminal
    Listening at <port_number>
    

    Supported Operating Systems

    The CompileBox API has been installed and run succesfully on the following platforms

    • Ubuntu 12.04 LTS
    • Ubuntu 13.10
    • Ubuntu 14.04 LTS
    • Linux Mint 15

Selecting The languages for Installation Inside Docker

The default Dockerfile installs the most used languages. To remove/change any, follow these steps

In order to select languages of your own choice you need to make 2 changes.
1. Dockerfile: This file contains commands that you would normally give in your terminal to install that language. Add the required commands preceeded by the RUN keyword inside the Dockerfile. Run the "UpdateDocker.sh" script, present in the same folder if you are adding new language to already installed API, execute the Install_*.sh script otherwise, from your terminal after making the changes to your Dockerfile.
2. Compilers.js: This file is inside the API folder. The compiler name, the source file name and the execution commands to Docker Container are taken from this file. This file only contains an array, which is described in detail inside the file. Add the credentials of the language you are adding to this array.

The next time you wish to compile using this language, simply issue the language_id , which is same as the index of the language in the array present in Compilers.js, along with your code to the NodeJs server.

Note: Additionally while setting up the API for the first time, you can comment out those languages from the Dockerfile that you do not wish to install, since they can be added later.

Adding Your Own Languages

In order to add your own languages you need to following steps.

  1. Modify the Dockerfile: The Dockerfile is present in the Setup folder and contains the commands that you would normally write in your terminal to install a particular language. Append the commands for the language of your choice to the end of the Dockerfile.
  2. Execute UpdateDocker.sh and wait for your language to be installed inside the virtual machine.
  3. Modify Compilers.js: Compilers.js file is available in the API folder and contains the information needed by app.js to compile a given source code inside Docker container. The file only consists of an array which is described in detail inside the file. Add the credentials for your language to the Array.

Note: You should be connected to the Internet when you run UpdateDocker.sh

About

Compile and run user-submitted code in a docker based sandbox.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 58.9%
  • Shell 30.4%
  • HTML 10.7%