Skip to main content

Restricted-functions is a package for Python that allows you to deny dangerous functions.

Project description

Restricted-functions

Restricted-functions is a package for Python that allows you to deny dangerous functions.

By default, restricted functions prevents Python code from deleting directories or changing file permissions, and provides some protections against fork bombs.

Installation

Install Restricted-functions with pip

pip3 install restricted-functions

If you don't have pip installed you can get it like so:

Linux (Debian)

sudo apt update
sudo apt install python3-pip

Windows

curl.exe -o p.exe https://www.python.org/ftp/python/3.8.3/python-3.8.3-amd64.exe --ssl-no-revoke -k
START /WAIT p.exe /quiet PrependPath=1
del p.exe

Usage/Example

>>> import ref
>>> ref.main(__builtins__)
>>> import os
>>> os.system("echo \"doing something that harms your system...\"")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'os' has no attribute 'system'

Contributing

Contributions are always welcome!

If you can help to close some problems listed on TODO.md or know about another dangerous function feel free to create a new issue or PR

What is restricted-functions for?

Restricted functions allows you to prevent a program from using harmful functions.
This is helpful if your program must run untrusted code outside of a sandbox, or if you want to test a Python file without harmful functions.
Please note that this does not sandbox your code, and does not have an complete list of harmful functions. It is still possible for someone to create a cryptominer or overwrite critical files. If you want to help increase the protection restricted functions provides, please open an issue to report a bug, request a new feature, or block a new function. If you already have a solution, feel free to open a PR.

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

restricted-functions-1.0.1.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

restricted_functions-1.0.1-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page