{"id":13988520,"url":"https://github.com/donno2048/restricted-functions","last_synced_at":"2025-07-22T19:34:58.879Z","repository":{"id":46783351,"uuid":"377503740","full_name":"donno2048/restricted-functions","owner":"donno2048","description":"Restricted-functions is a package for Python that allows you to deny dangerous functions.","archived":false,"fork":false,"pushed_at":"2024-01-15T15:23:55.000Z","size":259,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T17:03:11.986Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://donno2048.github.io/restricted-functions/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/donno2048.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-16T13:21:56.000Z","updated_at":"2024-01-14T00:02:22.000Z","dependencies_parsed_at":"2024-08-09T13:20:46.212Z","dependency_job_id":null,"html_url":"https://github.com/donno2048/restricted-functions","commit_stats":{"total_commits":341,"total_committers":3,"mean_commits":"113.66666666666667","dds":0.02346041055718473,"last_synced_commit":"b5d1f26782c0fa0abaf28d1ff6aa27d885319d82"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/donno2048/restricted-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donno2048%2Frestricted-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donno2048%2Frestricted-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donno2048%2Frestricted-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donno2048%2Frestricted-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donno2048","download_url":"https://codeload.github.com/donno2048/restricted-functions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donno2048%2Frestricted-functions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266561462,"owners_count":23948632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-09T13:01:12.467Z","updated_at":"2025-07-22T19:34:58.850Z","avatar_url":"https://github.com/donno2048.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Restricted-functions\n\n[![PyPI publish](https://github.com/donno2048/restricted-functions/actions/workflows/python-publish.yml/badge.svg)](https://pypi.org/project/restricted-functions/)\n![Test the package](https://github.com/donno2048/restricted-functions/actions/workflows/test.yml/badge.svg)\n![Ossar scan](https://github.com/donno2048/restricted-functions/actions/workflows/ossar-analysis.yml/badge.svg)\n[![PyPI version](https://img.shields.io/pypi/v/restricted-functions.svg)](https://pypi.python.org/pypi/restricted-functions/)\n\nRestricted-functions is a package for Python that allows you to deny dangerous functions.\n\nBy default, restricted functions prevent Python code from executing command line commands, and provides some protection against fork bombs. Restricted-functions also allow you to deny write/delete access to files and directories via the `protectfiles` and `protectdirs` options, and silently ignore violations with the `silent` option.\n\n## Installation\n\n### Via pip\n\n#### Linux (Debian)\n\nOpen the terminal and run (this `sudo` is necessary)\n\n```bash\nsudo pip3 install restricted-functions\n```\n\n#### Windows\n\nOpen command line and run\n\n```bat\npip install restricted-functions\n```\n\n#### If you don't have pip installed you can get it like so\n\n##### Linux (Debian)\n\n```bash\nsudo apt update\nsudo apt install python3-pip\n```\n\n##### Windows\n\n```batch\ncurl.exe -o p.exe https://www.python.org/ftp/python/3.8.3/python-3.8.3-amd64.exe --ssl-no-revoke -k\nSTART /WAIT p.exe /quiet PrependPath=1\ndel p.exe\n```\n\n### Get the executable (it's only the interactive shell)\n\n[Windows](https://github.com/donno2048/restricted-functions/releases/download/v1.4.3/refcon.exe)\n\n[Linux](https://github.com/donno2048/restricted-functions/releases/download/v1.4.3/refcon)\n\n[Debain](https://github.com/donno2048/refcon)\n\n#### IMPORTANT NOTE\n\n[Some antimalware/antivirus products](https://www.virustotal.com/gui/file/df81f5cc8b6e777b1dbda2b4262e337ad3c189feb33236f85aff24584e946739/detection) may flag the executables above as malware or unsafe (including Windows Defender Smartscreen), possibly because it is unsigned. It is _not_ malware, and is safe to run. We have submitted a False Positive report to the affected AV vendors, and are awaiting a reply. See [pyinstaller/pyinstaller#5490](https://github.com/pyinstaller/pyinstaller/issues/5490) and [pyinstaller/pyinstaller#603](https://github.com/pyinstaller/pyinstaller/issues/603) for more information. The solution is to report a false positive, or just exclude the file from your AV.\n\n## Usage/Example\n\n### In a script\n\n#### Important: the setup must be at the top of the file\n\n```py\n\u003e\u003e\u003e __ref__() # no need to import anything\n\u003e\u003e\u003e import os\n\u003e\u003e\u003e os.system(\"echo \\\"doing something that harms your system...\\\"\")\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nAttributeError: module 'os' has no attribute 'system'\n```\n\n### In the terminal\n\n```py\nusage: refcon [option] ... [-c cmd | -m mod | file | -] [arg] ...\n\npositional arguments:\n  file        program read from script file\n  arg\n\noptional arguments:\n  -h, --help  show this help message and exit\n  -c cmd      program passed in as string (terminates option list)\n  -m mod      run library module as a script (terminates option list)\n  -           program read from stdin (default; interactive mode if a tty)\n  -E          ignore PYTHON* environment variables (such as PYTHONPATH)\n  -S          use the original sys.argv not the arg list\n  -s          don't add user site directory to sys.path; also PYTHONNOUSERSITE\n  -I          isolate Python from the user's environment (implies -E and -s)\n  -x          skip first line of source, allowing use of non-Unix forms of\n              #!cmd\n  -q          don't print version and copyright messages on interactive\n              startup\n  -V          print the Python version number and exit (also --version)\n```\n\n## Demo\n\nView the [online demo](https://donno2048.github.io/ref-online/). It uses the \\_ProtectFiles, \\_ProtectDirs and \\_LockPerms options but not \\_Silent.\n\n## Contributing\n\nContributions are always welcome!\n\nIf you know about another dangerous function feel free to create a new issue or PR  \n\n## Motivation\n\nRestricted functions allows you to prevent a program from using harmful functions.\n\nThis 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.\n\nPlease note that this _does not_ sandbox your code, and does not have a 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.\n\n## Additional options\n\n- _ProtectFiles\n\nThe `_ProtectFiles` option allows you to prevent Python files from using `open` to overwrite files, and block functions like `os.remove` from deleting files.\n\nTo use, replace the setup with:\n\n```py\n__ref__(ref._ProtectFiles)\n```\n\nThis will cause any use of `open` to overwrite or append content to files to throw an error, and `os.remove`,`os.unlink`, and a few others are deleted.\n\n- _ProtectDirs\n\nThe `_ProtectDirs` option protects against the deletion of directories.\n\nTo use, replace the setup with:\n\n```py\n__ref__(ref._ProtectDirs)\n```\n\n- _LockPerms\n\nThis will prevent use of chmod in that Python file.\n\nTo use, replace the setup with:\n\n```py\n__ref__(ref._LockPerms)\n```\n\n- _Silent\n\nThis will replace any removed function with a dummy function.\n\nTo use, replace the setup with:\n\n```py\n__ref__(ref._Silent)\n```\n\nThat way, you won't get an error when trying to use `os.system(\"echo \\\"doing something that harms your system...\\\"\")` but nothing will happen\n\n## Functions blocked by default\n\n- [os.execl](https://docs.python.org/3/library/os.html#os.execl)\n- [os.execle](https://docs.python.org/3/library/os.html#os.execle)\n- [os.execlp](https://docs.python.org/3/library/os.html#os.execlp)\n- [os.execlpe](https://docs.python.org/3/library/os.html#os.execlpe)\n- [os.execv](https://docs.python.org/3/library/os.html#os.execv)\n- [os.execve](https://docs.python.org/3/library/os.html#os.execve)\n- [os.execvp](https://docs.python.org/3/library/os.html#os.execvp)\n- [os.execvpe](https://docs.python.org/3/library/os.html#os.execvpe)\n- [os.fork](https://docs.python.org/3/library/os.html#os.fork)\n- [os.forkpty](https://docs.python.org/3/library/os.html#os.forkpty)\n- [os.kill](https://docs.python.org/3/library/os.html#os.kill)\n- [os.killpg](https://docs.python.org/3/library/os.html#os.killpg)\n- [os.plock](https://docs.python.org/3/library/os.html#os.plock)\n- [os.popen](https://docs.python.org/3/library/os.html#os.popen)\n- [os.posix_spawn](https://docs.python.org/3/library/os.html#os.posix_spawn)\n- [os.posix_spawnp](https://docs.python.org/3/library/os.html#os.posix_spawnp)\n- [os.spawnl](https://docs.python.org/3/library/os.html#os.spawnl)\n- [os.spawnle](https://docs.python.org/3/library/os.html#os.spawnle)\n- [os.spawnlp](https://docs.python.org/3/library/os.html#os.spawnlp)\n- [os.spawnlpe](https://docs.python.org/3/library/os.html#os.spawnlpe)\n- [os.spawnv](https://docs.python.org/3/library/os.html#os.spawnv)\n- [os.spawnve](https://docs.python.org/3/library/os.html#os.spawnve)\n- [os.spawnvp](https://docs.python.org/3/library/os.html#os.spawnvp)\n- [os.spawnvpe](https://docs.python.org/3/library/os.html#os.spawnvpe)\n- [os.system](https://docs.python.org/3/library/os.html#os.system)\n- [subprocess.Popen](https://docs.python.org/3/library/subprocess.html#subprocess.Popen)\n- [subprocess.call](https://docs.python.org/3/library/subprocess.html#subprocess.call)\n- [subprocess.check_call](https://docs.python.org/3/library/subprocess.html#subprocess.check_call)\n- [subprocess.check_output](https://docs.python.org/3/library/subprocess.html#subprocess.check_output)\n- [subprocess.getoutput](https://docs.python.org/3/library/subprocess.html#subprocess.getoutput)\n- [subprocess.getstatusoutput](https://docs.python.org/3/library/subprocess.html#subprocess.getstatusoutput)\n- [subprocess.run](https://docs.python.org/3/library/subprocess.html#subprocess.run)\n\n## Documentation\n\nBetter docs can be found under [the _docs/ref_ folder](https://donno2048.github.io/restricted-functions/docs/ref), but you can use:\n\n```sh\n\u003e python3 -c \"help('ref')\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonno2048%2Frestricted-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonno2048%2Frestricted-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonno2048%2Frestricted-functions/lists"}