Git Product home page Git Product logo

pythonbox's Introduction

pythonbox

Simple service to run Python 3 sandboxed in a Docker container and return the output back.

Motivation

I originally tried to use Judge0 to do this, but it turns out that Judge0 only runs on systems with cgroups v1 enabled, and my current setup only supports cgroups v2. Running code in a Docker container is pretty safe (as long as you don't privilege the container), so this is what this we do to contain the code. Right now it only supports python, but it is very simple to extend this in the future to other scripting languages as long as they can run in a docker container.

For compilation, we might need to introduce a multiple entry script system, but that is a TODO at the moment.

Installation

  1. Ensure you have installed docker and the rust toolchain.
  2. Ensure that the current user has permissions to use docker.
  3. git clone the repository, and run cargo build inside

Running the server

  1. Run ./run.sh

Requests

Post requests in JSON to the endpoint /run_code.

Each request must have the following fields:

  • max_time_s: number, in secconds that the code can run for
  • base_64_tar_gz: string containing a base 64 representation of a tar file containing the code. The tar file must contain an executable file called run at it's base. run should run the main Python script. The entire tar will be unpacked in the /opt directory.

If the HTTP response status code is 200 the response will be a JSON object with the following fields:

  • stdout: base 64 encoded string containing the stdout of the program
  • stderr: base 64 encoded string containing the stdout of the program
  • exit_code: the exit code of the program (may be null if we couldn't get the code)

pythonbox's People

Contributors

pimpale avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.