Skip to main content

A lightweight Python package for analyzing and securely executing code blocks with AST-based restrictions.

Project description

Python Restrictor & Executor

Overview

A sandboxed Python code execution environment with support for ast-based validation, restricted imports and builtins, and multiple execution methods including subprocesses and uv.


Installation

pip

pip install restricted

uv

uv add restricted

Usage

from restricted.helpers import execute_restricted

# A block of code pretending to be malicious.
code="""
import os
print(os.getcwd())
"""

print(execute_restricted(code))

# Shell Output
ImportError: 'os' is not allowed

Security Notice

This project is in early development and should not be considered production-ready for high-risk environments.

Contribution

If you want to contribute to this small project, feel free to submit a pull request here.

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-0.1.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

restricted-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file restricted-0.1.0.tar.gz.

File metadata

  • Download URL: restricted-0.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for restricted-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4ac03845ef893dd644038a08e70fe8d2cab47e6c8cb34f5ca3f6117d67f3a37
MD5 e893bc557645d861ff759f89fc2afa32
BLAKE2b-256 ffbd7eac62c90be336ca327a0950197fbbf0dd7ff1d7318dd23500727eedbe84

See more details on using hashes here.

File details

Details for the file restricted-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: restricted-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for restricted-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6c75f9dd5084af9d54ad42259511ca886dba78eaefd1bcea2a5f394509c11a7
MD5 6d54e16a10e731dc2382a126403f6a65
BLAKE2b-256 2e2688b7f59c31911ba7231a1a0b244d1a9b3616ca8268b4673de247ec3c67b8

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