Skip to main content

A Python module for sandboxing code execution.

Project description

PyJail

PyJail is a Python module designed to provide a secure environment for executing untrusted code. PyJail is available on PyPI.

pip install PyJail

To execute a function without access to your system, call it through PyJail as shown below.

from pyjail import Jail

with Jail() as jail:
    result = jail.execute(untrusted_func, args=func_args, kwargs=func_kwargs)

The Jail class constructor has the optional parameters path=os.path.join(os.getcwd(), "jail"), clear_before_create=False and clear_after_destroy=True. The path parameter specifies the directory where the jail will be created. The clear_before_create parameter specifies whether the jail directory should be cleared before creation (if it already exists) and the clear_after_destroy parameter specifies whether the jail directory should be cleared after destruction.

The execute method takes the optional parameters args (positional arguments) and kwargs (keyword arguments) to pass arguments to the function untrusted_func. The execute method also takes an optional timeout parameter to specify the maximum time in seconds that the function is allowed to run. A TimeoutError will be raised if the function takes longer than the specified time to execute. Otherwise, the return value of the function is returned (and exceptions are raised if the function raises an exception).

[!NOTE] You must run your python script as root to create a jail.

[!NOTE] PyJail is currently only supported on Linux.

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

PyJail-0.1.4.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

PyJail-0.1.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file PyJail-0.1.4.tar.gz.

File metadata

  • Download URL: PyJail-0.1.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for PyJail-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ec250405e0591593256dabd9e35b91bf137ac18d09ca7d963c45a0eb0cb9a198
MD5 21619514b9b90bd54cfd3ae1aa3764fb
BLAKE2b-256 899981ac7b41abc2079d535ce09f082b6ca043f24f6e6d159d9f77128c4f4e52

See more details on using hashes here.

File details

Details for the file PyJail-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: PyJail-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for PyJail-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6d642a383428ad0fbf9711d1039ec6ab7d434d4c3ee579c8c14f798e18bf7fb4
MD5 689f11dc34aa19718175b17d449f8c2c
BLAKE2b-256 63d5a33b7bdb0d44cd6a52c697420749f81929cc943bc9bbbb42294ce03f447f

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