A Python module for sandboxing code with restricted imports and timeout enforcement (Linux/macOS only)
Project description
PySandboxing
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...
Installation
From PyPI
pip install pysandboxing
From Source
To install PySandboxing, clone the repository and run the setup script:
git clone https://github.com/libardoram/pysandboxing.git
cd pysandboxing
python setup.py install
Example Usage
To 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
Features
- 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.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Libardo Ramirez Tirado - libar@libardoramirez.com
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysandboxing-0.1.2.tar.gz.
File metadata
- Download URL: pysandboxing-0.1.2.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bd7a15df27c4dc72cdf54bc3d26c31df1dbc54414b18af95b70c93bd44b5e72
|
|
| MD5 |
311ba4bc3feec309a917051432b64a0c
|
|
| BLAKE2b-256 |
445760ddafcfea26e637f16624b58a05e1499b6a8fadd72f8774151719e9cbb6
|
File details
Details for the file pysandboxing-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pysandboxing-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
845849c5824dce9ca31ed9789363e0f6e93c6ec42f56a7759a042fcf7efa8546
|
|
| MD5 |
d42c21095f681ec3aae90fe079179c08
|
|
| BLAKE2b-256 |
f30fd5b3cf439a37dff10ea3518ca7dc7a76210f189b7be7437cabd15c79ca34
|