Skip to main content

Codejail plugin for Tutor

Codejail is a Python library used to manage the execution of Python code in a sandboxed environment.

This plugin configures and runs a remote CodeJail Service instance that implements the safe-exec API used by the Open edX platform to offer more advanced capabilities to course authors.

Installation

To install the latest version, run:

pip install tutor-contrib-codejail
# or install from the source
pip install git+https://github.com/edunext/tutor-contrib-codejail

Requisites

By it's very nature of allowing arbitrary code execution, the CodeJail service must be run under a hardened environment. The security guarantees are enforced through AppArmor security profiles and thus necessitates the use of a Linux host with support for AppArmor security module (usually Debian derived distributions).

You can validate if your Linux host has AppArmor enabled by running:

aa-enabled

Configuration

To customize the configuration, update the following settings in Tutor:

  • CODEJAIL_APPARMOR_DOCKER_IMAGE: (default: docker.io/ednxops/codejail_apparmor_loader:latest)
  • CODEJAIL_DOCKER_IMAGE: (default: docker.io/ednxops/codejailservice:{{__version__}})
  • CODEJAIL_ENABLE_K8S_DAEMONSET (default: False)
  • CODEJAIL_EXTRA_PIP_REQUIREMENTS (default: [])
  • CODEJAIL_SANDBOX_PYTHON_VERSION (default: 3.12)
  • CODEJAIL_SERVICE_REPOSITORY (default: https://github.com/openedx/codejail-service.git)
  • CODEJAIL_SERVICE_VERSION (default: {{ OPENEDX_COMMON_VERSION }}),

Custom Image

In most cases, you can work with the provided Docker image for the release. However, there might be cases when a custom image will be necessary:

  • If you need additional packages installed in the sandbox environment. Use the setting CODEJAIL_EXTRA_PIP_REQUIREMENTS to define the list of additional packages.
  • If you need to run the sandbox environment under a different Python version you can use CODEJAIL_SANDBOX_PYTHON_VERSION. This is particularly useful when the sandbox version is upgraded between releases but you need to figure out a migration plan for instructor code.
  • If you need a completely different set of packages in the sandbox virtual environment. In this case you will need to point to a requirements file using the following docker build arguments: SANDBOX_DEPS_REPO, SANDBOX_DEPS_VERSION, SANDBOX_DEPS_SRC_DIR and SANDBOX_DEPS_SRC_FILE. Their current default values are https://github.com/openedx/codejail-service.git, {{ OPENEDX_COMMON_VERSION }}, requirements/sandbox and base.txt. This will point to https://github.com/openedx/codejail-service/blob/release/verawood.1/requirements/base.txt for the Verawood release. You can provide the arguments to Tutor as follows tutor images build codejail -a SANDBOX_DEPS_VERSION=ulmo2.

Kubernetes Support

The CodeJail service provides a sandbox to run arbitrary code. Security enforcement in the sandbox is done through AppArmor, this means that AppArmor must be installed in the host machine, and the provided profile must be loaded.

For Kubernetes environments, you must ensure each node has AppArmor installed and has successfully loaded the profile.

You can enable a helper Daemon Set that will load the profile onto all the nodes by setting CODEJAIL_ENABLE_K8S_DAEMONSET to true.

More info about this discussion can be found on this issue.

Testing Functionality

To verify if Codejail is working, use a course with loncapa problems in Studio and check for correct execution. You can import the provided example course.

Once the course is imported, go to any section and select an exercise (section example), the proper result is:

Example when codejail is working{.align-center width="725px"}

In this case, the section's content will render correctly and work as specified in the instructions of the problem.

New CodeJail Service implementation

The Ulmo release introduced support for deploying a new implementation of the remote CodeJail service (openedx/codejail-service). The Verawood release completely removes support for deploying the old version of the service (edunext/codejailservice). Users should be mindful of the following points when upgrading:

  1. The new CodeJail service requires AppArmor 4 on the host machine. AppArmor 4 is available on relatively new Debian based distributions (ubuntu 24.04, Debian Trixie, etc).
  2. AppArmor enforcement is no longer optional. The new CodeJail service performs startup checks to ensure the sandbox is properly isolated and will not start if the AppArmor profile is not loaded and configured.
  3. The new CodeJail service implementation is based on Django instead of Flask. Any usage of the codejail-*-settings must be adjusted accordingly.

License

This software is licensed under the terms of the AGPLv3. See the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tutor_contrib_codejail-22.0.1.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tutor_contrib_codejail-22.0.1-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file tutor_contrib_codejail-22.0.1.tar.gz.

File metadata

  • Download URL: tutor_contrib_codejail-22.0.1.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tutor_contrib_codejail-22.0.1.tar.gz
Algorithm Hash digest
SHA256 214fd4b2fc107761d4bddce216c91e81966532ef924dcf16cd9ab97710be4cc6
MD5 a6d4fe771fb6a115126c9f2182f439c6
BLAKE2b-256 987f214934398d4a3fe52fd67f77c0270fd58de53fd516eca1439b5c3555f3ec

See more details on using hashes here.

File details

Details for the file tutor_contrib_codejail-22.0.1-py3-none-any.whl.

File metadata

  • Download URL: tutor_contrib_codejail-22.0.1-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tutor_contrib_codejail-22.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8304650c7550aad5459649a181e9f715274645e48465a4408e079a3d250134b0
MD5 daa51e9d5d67cd797744ed4ee62419f3
BLAKE2b-256 7e8f752402cf5a2c3fb182af122d2e6170fc2661998b604687c4ba277d05762f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

22.0.1 This release

2 files

22.0.0

2 files

21.0.1

2 files

21.0.0

2 files

20.1.0

2 files

20.0.0

2 files

19.1.1

2 files

19.1.0

2 files

19.0.0

2 files

18.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page