Metadata-Version: 2.1
Name: PyJail
Version: 0.1.4
Summary: A Python module for sandboxing code execution.
Home-page: https://github.com/mrigankpawagi/PyJail
Author: Mrigank Pawagi
Author-email: Mrigank Pawagi <mrigankpawagi@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/mrigankpawagi/PyJail
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE.txt

# PyJail

PyJail is a Python module designed to provide a secure environment for executing untrusted code. PyJail is available on [PyPI](https://pypi.org/project/PyJail/).

```bash
pip install PyJail
```

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

```python
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.
