Skip to main content

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

  1. Disables dangerous built-in functions (exec, eval, open).
  2. Restricts the import of certain modules to prevent security risks.
  3. 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

pysandboxing-0.1.4.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

pysandboxing-0.1.4-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysandboxing-0.1.4.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for pysandboxing-0.1.4.tar.gz
Algorithm Hash digest
SHA256 98e1f6dca60a38d4a80927e0335018001e9208c819414ad77f64e2e0e995ece4
MD5 1e01da74ea37324cd651a48aaf029727
BLAKE2b-256 eec6315f70c9aaa045acbed94d2fed7ed352d10358eba5894ff4217ec1de664e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pysandboxing-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for pysandboxing-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 dd3d8c8d59bac819d3ff322500c06dd9964b50bb0df6e6d78da9f43f17174d5e
MD5 f9fb3543e4550387fe12bd6038f3c220
BLAKE2b-256 1ae10d29f20c27d9aae50d9c8860c85e84fe7cc7284f9ad0ec873ac56450f639

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