Skip to main content

Python virtual environment which jails executed programs.

Project description

venvjail: Python virtual environment which jails executed programs.

Development status: Planning

Overview

venvjail allows to install and run python programs without giving them full access to the user's account. The goal is to limit harm a compromised dependency can make without sacrificing the user’s convenience. venvjail offers very similar workflow to the standard Python venv, in most cases you should not notice and be affected by the additional limitations applied in the jailed venv.

venvjail uses Linux namespaces and runs without root privileges. It requires a Linux kernel with user namespaces enabled (for example, Ubuntu 22 default kernel).

The following restrictions are applied to the jailed processes by default:

  • The processes can write only to files in the directory subtree in which the venvjail was created. The exception are the venvjail activation and configuration files, which are not accessible in the jail.

  • The whole content of the home directory is hidden in the jail with the exception of an explicit list of configuration files which are available read-only. By default this list includes .bashrc, .profile, .bash_profile and can be modified via a ~/.dirjailconfig file.

  • The processes are allowed to create new files in the home directory (for example program config files), but all these created files are in fact stored in the ./home sub directory of the virtual environment.

  • The processes can read and write to the /tmp directory. Outside of the jail this directory points to the /tmp/dirjail-XXXXXX.

  • The process can see only processes that are executed in the same jail.

  • Most files in /proc and all files in /run/user/UID are not readable in venvjail.

  • Suid programs can not be executed in the jail.

  • All other files that you can normally read and execute are also readable and executable in the jail (but not writable). This can be also adjusted via the ~/.dirjailconfig file.

Compared to running a program in a separate virtual machine or a Docker instance, the following conveniences improve the user experience:

  • The jail runs on top of your current distribution, so you can run all the programs that you have available on your machine. Of course, these executed programs are also jailed, so for example ls ~ will only list files visible in the jail.

  • Your username is preserved in the jail. You are not a root, and files owned and created by you are listed as such in the jail.

  • An explicitly selected list of config file are exposed to the jail in read-only mode. Shell configuration, helper functions, aliases continue to work normally while in the jail.

  • Your current working directory path and most of the directory structure is preserved in the jail.

  • File system modifications done in the jail are limited to the jailed directory subtree, so you can be sure that removing this program directory removes all the files that the program created. This helps to keep the system tidy.

Installation and usage

To install run:

pip install venvjail

To create a virtual environment in a venv directory:

python -m venvjail venv

To start a new shell with the jailed virtual environment activated:

./venv/bin/activate-new-shell

Or:

source ./venv/bin/activate-new-shell

Like with the standard Python venv, you can run any program from the venv/bin directly without activating venv first, and all these programs are executed in the jail. For example:

  ./venv/bin/python
   >>> import os, pathlib
   >>> os.listdir(pathlib.Path.home());
   # You can see that most of the files in your home dir are hidden in the jail:
   ['.bashrc', '.profile, ...]

Where is the ./venv/bin/activate script and how to run scripts that source this file?

/venv/bin/activate script of the standard Python venv module activates the virtual environment in the current shell, this is why this script should be sourced and not executed. Because it is not possible to jail an already existing process, venvjail needs to create a new shell process, to avoid confusion the activation script is called ./venv/bin/activate-new-shell.

Once the venvjail is active, venv/bin/activate script becomes available, sourcing it is a no-op, because the venv is already activate, but it allows to run existing shell scripts that call source/venv/activate.

Project details


Download files

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

Source Distribution

venvjail-0.0.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

venvjail-0.0.0-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file venvjail-0.0.0.tar.gz.

File metadata

  • Download URL: venvjail-0.0.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for venvjail-0.0.0.tar.gz
Algorithm Hash digest
SHA256 1e114b6727f3fdacb46528c6242437417ec6a4fb58b5e67e9a7627312f06615e
MD5 16c8b050d1395fe7f6c490c63adc04f3
BLAKE2b-256 32261a9f60c09f1d2df52a8177e03b15a64822f87d596a67c80c2ea8886d3ae4

See more details on using hashes here.

File details

Details for the file venvjail-0.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: venvjail-0.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for venvjail-0.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f5f859c1d7ad47edaa2df3660d484d10ad554a78f53ecaf1553a8d43778bbd6f
MD5 46fa963f5706eaee07dd98e1477e7587
BLAKE2b-256 b5599c8761cc1bfaed47f873f5a2d7e2852df2539d1156d45523ac9409b64b9b

See more details on using hashes here.

Supported by

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