Giter VIP home page Giter VIP logo

codebox's People

Contributors

andredias avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

bleso-a

codebox's Issues

Improve/remove class NsJail

It seems possible to limit the amount of memory using rlimit_as and file size using rlimit_fsize. This way, I'm not sure if using NsJail cgroups is still necessary. If not, it would be possible to get rid of NsJail class and call execute directly.

It is also worth investigating if it will be possible to run the container using nobody as the user.

Use Async subprocess calls

Codelab used to use this a while ago. Not sure if this could improve performance, but it is worth it a try.

Improve Codebox based on Snekbox

Python Discord has a very similar sandbox container called snekbox which uses some very good ideas that we can also apply in codebox:

  1. It is based on HTTP instead of stdin, stdout, stderr
  2. It uses NsJail to create sandboxed processes. Using it, we might create a unique container to serve all jobs instead of spinning up a container for each project. Or even better, we can drop the additional container at all.

There is another similar project called Piston that is based on LXC containers that might be useful too.

Prevent redundant transformations in FastAPI entry points

/projects entry, for example, transforms an array of projects in JSON from Redis into an array of Pydantic Objects that will be transformed at the end into a JSON array by FastAPI. There must be some way to return the information closer to the way it comes from Redis.

Replace nsjail with minijail

Nsjail documentation is very scarce. It is hard to find anything even on Google. For example, I couldn't find an example about how to declare a parameter for a mounting point with a limit size. (--mount /tmp/sandbox_234:/sandbox:??:??,size=200m).

On the other hand, minijail is an official Google project and it seems to have better documentation. It is yet to see how hard would be to replace nsjail.

Test Coverage doesn't work when code runs in a container

Current tests make calls to REST API in a running container. So, test coverage doesn't work well and gives wrong statistics. To get better results, tests must run inside the container, following the pattern to call the app directly, as used in ordinary FastAPI tests.

As codebox doesn't have external dependencies, we might use something like:

docker run --rm -it --privileged --init -e ENV=TESTING --ipc=none \
      -v $(pwd)/tests:/codebox/tests \
      --name codebox codebox pytest -svx

Make common Python packages available to Python projects

Some common packages such as isort, blue, flake8 etc. should be available to Python projects or Codebox's clients to lint code or something like that.

The packages should be installed in a different virtual environment directory that will be made available later to the jail environment through a directory called /.venv. This directory should also be added to the PATH environment variable to the jail environment.

Probably, the best way to install those packages is from the Dockerfile. Also, we might use a Docker volume to keep and update those packages.

It is worth investigating whether PYTHONPATH or PYTHONUSERBASE is the best envvar to keep the new path, or if PATH is enough.

Snekbox has a similar concept. See its README.

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.