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
Release history Release notifications | RSS feed
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
Hashes for restricted-functions-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b183cb786314850a50ce43de44f3e1680247b6333f761a330f9344e8b7b9cebe |
|
MD5 | 68b38b2a4b9eac98e7dd591644e80ab0 |
|
BLAKE2b-256 | ccbf42eac3193a4cb1bf5b6fe1533792a4a4665f7d5a70e6bbd0a1572d07fe5b |
Hashes for restricted_functions-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a696d9cd4bcf22ed5527c14e4265769e9664e0b4d10fae0be4d0047c267e4e51 |
|
MD5 | b5769ad1c654f312e1ba189f49ac8e87 |
|
BLAKE2b-256 | e448c5ed9ecc23862b27601376a1a729bf72c41e8eb7ab93621f1ab6c14fa696 |