PremierLangage / sandbox

A sandbox to execute foreign code using docker
MIT License
8 stars 5 forks source link

Python package codecov CodeFactor Documentation Python 3.8+ License MIT

Installation

Requirements:

To deploy the sandbox, you also need apache2.

Installation

Installing the server is pretty straightforward, you just need to clone the repository and run the install script :

git clone https://github.com/PremierLangage/sandbox.git
cd sanbox
./bin/install.sh  

The sandbox can now be run : python3 manage.py runserver [port].

Deploying

If you also want to deploy the server, run ./bin/deploy.sh. You may want to check the created config file at /etc/apache2/sites-enabled/sandbox-auto.conf.

You will then have to restart apache2 : systemctl restart apache2 or service apache2 restart.

Endpoints

POST /execute/

Execute commands on the sandbox with the given environment, or an environment already present on the sandbox.

Request

Body must be encoded in form_data and must contains a json containing informations about the execution:

{
    "commands":[
        "<bash command 1>",
        { 
            "command": " -<bash command 2>",
             "timeout": 2
        },
        { 
            "command": "-<bash command 3>",
             "timeout": 5
        },
    ],
    "environ": {
            "var1": "value1",
            "var2": "value2"
    },
    "result_path":"file.json",
    "environment": "<UUID4>",
    "save": "<bool>",
}

Mandatory fields :

Optionnal fields :

The body can also contain an Optionnal tar archive compressed with gzip (.tgz or .tar.gz) of your environment of execution. If field environment is present in the JSON, the file present in the body's environment will be added to the one in the sandbox, overwritting file with the same name.

Response

The response is a json such as :

{
  "status": 0,
  "execution": [
    {
      "command": "echo $((1+1)) > result.txt",
      "exit_code": 0,
      "stdout": "",
      "stderr": "",
      "time": 0.002222299575805664
    }
  ],
  "total_time": 0.004444599151611328,
  "result": "2",
  "environment": "e8c5995b-7049-4b04-8440-5d9d914360fc",
  "expire": "20190705T130535Z"
}

The status fields in the reponse indicate whether the execution succeeded or failed :

execution contains the details of each executed commands.

The response's total_time is the total time taken by the whole execute request, it thus can be higher than the sum of each command's time.

for environment, expire and result, see the result_path and save keys of the request's config json.

GET /environments/:uuid4/

Retrieve the environment (as a .tgz) corresponding to the uuid4.

GET /files/:uuid4/:path/

Used to retrieve a file in a specific environment. Response's Content-Type will always be application/octet-stream.

GET /specifications/

Retrieves informations about the sandbox, like the specifications of the containers, and the number of running containers.

Field container -> memory -> storage can be equal to -1 if no limit was set.

CPU frenquencies are in MHz.

Memory values are in bytes.

GET /libraries/

Returns the librairies installed in the containers.

GET /usages/

Return current usage of the sandbox.

CPU frenquencies are in MHz.

Memory and I/O values are in bytes.