wasm-py-sandbox


Namewasm-py-sandbox JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/JSH32/PySandbox
SummarySandbox environment for executing Python code
upload_time2023-11-15 08:23:57
maintainer
docs_urlNone
authorJosh Rudnik
requires_python>=3
licenseMIT
keywords python sandbox wasm wasmer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python Sandbox
This python sandbox uses wasmer to execute untrusted python code in a sandbox. It is expiremental and limited in functionality. This was designed to be used in an assignment autograder.

## Components
- Rust WASM layer
  - [RustPython](https://github.com/RustPython/RustPython) is used as a dependency in the rust part of this library. RustPython doesn't aim to create sandboxed environments but we can create a simple API for interacting with it while it is being run in a `wasm32-wasi` runtime which would effectively sandbox it.
  - We use [WAI](https://github.com/wasmerio/wai) to generate glue implementations that we can use to interop between a regular Python environment and RustPython.
- Python Layer
  - The Python bindings are also generated with WAI and a helper is provided for setup.

## Development
You will need Rust and `wai-bindgen` installed from [WAI](https://github.com/wasmerio/wai).
- To compile the Rust code to a WASI binary, run `cargo build --release --target wasm32-wasi`
  - Replace `py_sandbox/py_sandbox.wasm` with `target/wasm32-wasi/release/py_sandbox.wasm` after building to see changes.
- To build new `bindings.py` from `sandbox.wai`, run `wai-bindgen wasmer-py --import ./sandbox.wai`

## Usage
```py
from wasm_py_sandbox import create_sandbox

# each sandbox has its own memory.
sandbox = create_sandbox()

# returns stdout/err
stdout = sandbox.exec("""
def hello(x):
    return x + 5
""")

# result has both stdout/err and return value
result = sandbox.eval("2+2")
print(result.value.value)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/JSH32/PySandbox",
    "name": "wasm-py-sandbox",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "python,sandbox,wasm,wasmer",
    "author": "Josh Rudnik",
    "author_email": "rudnik7000@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9a/a5/6466821c56b73de3494a7d95240a3152d945b2c9da0ae86d78926143ef38/wasm_py_sandbox-0.1.1.tar.gz",
    "platform": null,
    "description": "# Python Sandbox\nThis python sandbox uses wasmer to execute untrusted python code in a sandbox. It is expiremental and limited in functionality. This was designed to be used in an assignment autograder.\n\n## Components\n- Rust WASM layer\n  - [RustPython](https://github.com/RustPython/RustPython) is used as a dependency in the rust part of this library. RustPython doesn't aim to create sandboxed environments but we can create a simple API for interacting with it while it is being run in a `wasm32-wasi` runtime which would effectively sandbox it.\n  - We use [WAI](https://github.com/wasmerio/wai) to generate glue implementations that we can use to interop between a regular Python environment and RustPython.\n- Python Layer\n  - The Python bindings are also generated with WAI and a helper is provided for setup.\n\n## Development\nYou will need Rust and `wai-bindgen` installed from [WAI](https://github.com/wasmerio/wai).\n- To compile the Rust code to a WASI binary, run `cargo build --release --target wasm32-wasi`\n  - Replace `py_sandbox/py_sandbox.wasm` with `target/wasm32-wasi/release/py_sandbox.wasm` after building to see changes.\n- To build new `bindings.py` from `sandbox.wai`, run `wai-bindgen wasmer-py --import ./sandbox.wai`\n\n## Usage\n```py\nfrom wasm_py_sandbox import create_sandbox\n\n# each sandbox has its own memory.\nsandbox = create_sandbox()\n\n# returns stdout/err\nstdout = sandbox.exec(\"\"\"\ndef hello(x):\n    return x + 5\n\"\"\")\n\n# result has both stdout/err and return value\nresult = sandbox.eval(\"2+2\")\nprint(result.value.value)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Sandbox environment for executing Python code",
    "version": "0.1.1",
    "project_urls": {
        "Bug Reports": "https://github.com/JSH32/PySandbox/issues",
        "Documentation": "https://github.com/JSH32/PySandbox",
        "Homepage": "https://github.com/JSH32/PySandbox",
        "Source Code": "https://github.com/JSH32/PySandbox"
    },
    "split_keywords": [
        "python",
        "sandbox",
        "wasm",
        "wasmer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1a266254051a77dbec826c100b3a19a085d21856c2449c0a10b6e7ff9d9d44ef",
                "md5": "c7f9cb4d10f5c530fd0915f5aad32e20",
                "sha256": "4989f407bd3ebbb108601e28fe5f426a47bc12df422b7eeefa120d34b35b512d"
            },
            "downloads": -1,
            "filename": "wasm_py_sandbox-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c7f9cb4d10f5c530fd0915f5aad32e20",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 3504489,
            "upload_time": "2023-11-15T08:23:55",
            "upload_time_iso_8601": "2023-11-15T08:23:55.536423Z",
            "url": "https://files.pythonhosted.org/packages/1a/26/6254051a77dbec826c100b3a19a085d21856c2449c0a10b6e7ff9d9d44ef/wasm_py_sandbox-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9aa56466821c56b73de3494a7d95240a3152d945b2c9da0ae86d78926143ef38",
                "md5": "8b4fc62e5236876de68e6be27883aef6",
                "sha256": "73f11645ffc92211aed994d44538547355b75993cc468cad94d087107e5c83a2"
            },
            "downloads": -1,
            "filename": "wasm_py_sandbox-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8b4fc62e5236876de68e6be27883aef6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 3476928,
            "upload_time": "2023-11-15T08:23:57",
            "upload_time_iso_8601": "2023-11-15T08:23:57.776136Z",
            "url": "https://files.pythonhosted.org/packages/9a/a5/6466821c56b73de3494a7d95240a3152d945b2c9da0ae86d78926143ef38/wasm_py_sandbox-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-15 08:23:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "JSH32",
    "github_project": "PySandbox",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "wasm-py-sandbox"
}
        
Elapsed time: 0.13984s