PySandboxing is a Python module for sandboxing code with restricted imports and timeout enforcement. It prevents the execution of dangerous built-in functions and restricts the import of certain modules to enhance security. Sort of...
pip install pysandboxingTo install PySandboxing, clone the repository and run the setup script:
git clone https://github.com/libardoram/pysandboxing.git
cd pysandboxing
python setup.py installTo use pysandboxing in your Python code, simply import the module at the beginning of your script:
import pysandboxing.sandbox
while True:
print("This will be stopped after the timeout!")import pysandboxing.sandbox as sandbox
import subprocess
subprocess.run(["ls", "-l"])You can also set an environment variable PYSANDBOX_TIMEOUT to specify the timeout duration in seconds. For example, to set a timeout of 6 seconds:
export PYSANDBOX_TIMEOUT=6- Disables dangerous built-in functions (exec, eval, open).
- Restricts the import of certain modules to prevent security risks.
- Enforces a timeout to stop possible infinite loops.
This project is licensed under the MIT License. See the LICENSE file for details.
Libardo Ramirez Tirado - libar@libardoramirez.com