Skip to main content

Sandboxed JavaScript execution for Python, via PyO3 + rquickjs.

Project description

quickjs-rs

Sandboxed JavaScript execution for Python.

Native Python extension (PyO3 + rquickjs) wrapping quickjs-ng (a QuickJS fork). Single self-contained wheel, zero runtime dependencies, microsecond-range runtime startup. ES modules with a composable scope registry. Inline TypeScript support via oxidase.

[!WARNING] quickjs-rs is experimental. Before putting this in production, you should read the Security guide.

Install

pip install quickjs-rs
uv add quickjs-rs

Wheels ship for Linux (x86_64 + aarch64), macOS (x86_64 + arm64), and Windows (x86_64), against Python 3.11, 3.12, and 3.13.

Quickstart

from quickjs_rs import Runtime

with Runtime() as rt:
    with rt.new_context() as ctx:
        assert ctx.eval("1 + 2") == 3

        # Register a Python callable as a JS global.
        @ctx.function
        def greet(name: str) -> str:
            return f"hi {name}"
        assert ctx.eval("greet('world')") == "hi world"

Async + top-level await:

import asyncio

async def main():
    with Runtime() as rt:
        with rt.new_context() as ctx:
            @ctx.function
            async def fetch_thing() -> str:
                await asyncio.sleep(0.01)
                return "from python"

            result = await ctx.eval_async("await fetch_thing()")
            assert result == "from python"

asyncio.run(main())

ES modules

Register modules via ModuleScope, then import them from module-mode eval. Scopes are recursive, self-contained resolver boundaries — each scope sees only what its own dict declares.

from quickjs_rs import ModuleScope, Runtime

stdlib = ModuleScope({
    "@agent/utils": ModuleScope({
        "index.js": """
            export { slugify } from './strings.js';
        """,
        "strings.js": """
            export function slugify(s) {
                return s.toLowerCase().replace(/ /g, '-');
            }
        """,
    }),
    "@agent/config": ModuleScope({
        "index.js": "export const MAX_RETRIES = 3;",
    }),
})

with Runtime() as rt:
    with rt.new_context() as ctx:
        rt.install(stdlib)
        assert await ctx.eval_async("""
            const { slugify } = await import("@agent/utils");
            const { MAX_RETRIES } = await import("@agent/config");
            slugify("Hello World") + '/' + MAX_RETRIES;
        """) == "hello-world/3"

Shared deps are declared by spreading (**utils.modules) into each scope that needs them. Resolver conventions are documented in AGENTS.md.

TypeScript

Source strings whose key ends in .ts, .mts, .cts, or .tsx are type-stripped at install() time via oxidase. Enums, namespaces, and parameter properties are transformed; plain type annotations erase to whitespace. No type checking — run tsc --noEmit separately if you want that.

rt.install(ModuleScope({
    "@util": ModuleScope({
        "index.ts": """
            export enum Mode { Strict = 1, Loose = 2 }
            export function slug(s: string, mode: Mode): string {
                return s.toLowerCase().replace(/ /g, mode === Mode.Strict ? '_' : '-');
            }
        """,
    }),
}))

TypeScript syntax errors surface at install() time (oxidase parses during stripping) rather than at eval.

Security

  • This library is not a host-memory isolation boundary. The JS engine (quickjs-ng via rquickjs/rquickjs-sys) runs in the same process/address space as Python.

    • When running untrusted or semi-trusted JS, run execution in isolated worker processes/containers with restricted network/filesystem access and recycle workers on timeout/OOM/failure.
  • Registered host callbacks are capability boundaries. Any callback exposed to JS should be treated as privileged if this runtime is being used to run untrusted code

  • Do not share a single Runtime across different trust domains/tenants. Use one runtime per trust domain to avoid cross-context module contamination.

See .github/THREAT_MODEL.md for more information on the threat boundaries and supply-chain posture of quickjs-rs

Development

# Dev install (maturin handles the Rust build).
pip install -e ".[dev]"
maturin develop --release

# Run tests, type-check, lint.
pytest
mypy quickjs_rs
ruff check

License

MIT. See LICENSE.

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

quickjs_rs-0.1.0.tar.gz (138.3 kB view details)

Uploaded Source

Built Distributions

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

quickjs_rs-0.1.0-cp313-cp313-win_amd64.whl (967.7 kB view details)

Uploaded CPython 3.13Windows x86-64

quickjs_rs-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

quickjs_rs-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (982.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

quickjs_rs-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (964.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

quickjs_rs-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

quickjs_rs-0.1.0-cp312-cp312-win_amd64.whl (967.3 kB view details)

Uploaded CPython 3.12Windows x86-64

quickjs_rs-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

quickjs_rs-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (982.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

quickjs_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (964.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

quickjs_rs-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

quickjs_rs-0.1.0-cp311-cp311-win_amd64.whl (969.4 kB view details)

Uploaded CPython 3.11Windows x86-64

quickjs_rs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

quickjs_rs-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (982.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

quickjs_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (963.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

quickjs_rs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: quickjs_rs-0.1.0.tar.gz
  • Upload date:
  • Size: 138.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for quickjs_rs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2e0a85c785d86d4d57d475f91d2538417518fd225ae7911f54d8d021f303838d
MD5 c7438d28482912ed2287cba75b360d54
BLAKE2b-256 3733024e9ea32bf1bee8dc60049dc37fcbdb07e838bc661ac74020f10ba18da1

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0.tar.gz:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: quickjs_rs-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 967.7 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for quickjs_rs-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6d16ea5d366bb2885f426f9cb37ea68e668409a940fea85b1015b3c58612a346
MD5 9d61556505b09f10706778f2b19dae78
BLAKE2b-256 dc651707487f5437b94ebcf1d69983673f8dce74aaefb44a7c560e2019b0159e

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6180aaaf7d64618c92845100dee9cba845c6ffcb73e8b4328ff02abbe8b639ac
MD5 587ee714b3fbe1df3ef9b038fcea4018
BLAKE2b-256 089849ad0065ac927cdca16f289ca5fc819b67ee2eed5dec4febe6751b4a9c46

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 35f1702417fb43049d18fa8bc7a01f3c9b7f651f758c32808368ce61aa58b8dd
MD5 879f67a0991e2fbf9f297d111071df66
BLAKE2b-256 34d54c50ad704ab58082d3d13a1eeeb774f4a7eb88b4e634590eda057153e9aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4d10697b3953b4e7d599ca6cf4c2b9a9510bc1eba368932e6bd0bb410e9951cf
MD5 fa114acc3ff6ad60dfe7c39087684fc4
BLAKE2b-256 d2a15052454cbef8bfc643e96b9d1d137f1928f0bf48e960bf0b77a3c333702d

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8e34472e522064f0db46fa7f92c14baeabbe9b158071145868c814699490a28f
MD5 d157d4dfeb614084ecb04445418fd686
BLAKE2b-256 9de111a2a78f8ba7c28279e2e8a058c4a38952547d07cfde2a8368cf05908522

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: quickjs_rs-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 967.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for quickjs_rs-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 71b0dddd27053cb270ddab537718b6e132b35f84d20368559d83b06293da17ac
MD5 724e1b65c9856d4335d39634c1225dbd
BLAKE2b-256 df4693d5b315db29075881630c6748c3c4838084291ad41e5ce3061d71cae310

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 02f2fffe796c4a45909208b06c7781135ad77ba78c7d27e0d46bcbc44b530387
MD5 39083cee84265022c5584390f3674a4c
BLAKE2b-256 c5f0056e1537de49bce75073019d963bfcc705114ef2dfebb5327da712f73937

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 685a77c7c04ea2dc51fa0e53b65477c7906a48d809acef8d9a4b65330925a7ab
MD5 830093aa99e4eb359483ad2caa2247e5
BLAKE2b-256 e43365261b05be1c7669aad8ad1dac2cff389dbc4a46f19be5dc1656fc2febae

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d973810a8f4ed6d119cb226867d47caa7f9c4073309a25bb14116c6d3b6d04b
MD5 cade97fbb757c5acfaf6fba697b034ef
BLAKE2b-256 a6a6f2352f13c640a96ed750ff3e64808f219c4dc18ff8f10c03aafd670cca38

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4a55fe742ca348f30ace35d9d76725536d6d013eeeddea9f97b2cc20710cf4e5
MD5 bc0042ee23ba8617473ebfe8c73db8d2
BLAKE2b-256 3c82044a06f5d97c9bfe5807ce35cda10864c09446aaf363b0e68de35e9aeeea

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: quickjs_rs-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 969.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for quickjs_rs-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 947fa051c99635da4a2151b17637550f48a0ddf0a7de639ab4d27d6d352eae59
MD5 48e58992920a5674a58d75b051f811bb
BLAKE2b-256 568245be566762c17dafbb782fdd1906790b4bccb2d63604fb3d98cd8eb82366

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff684c3f90f032b1e8449a3d8025f32470bfc5059f76c9292d68a755822bc3bc
MD5 e633f44f1a28111c49ed9d90d8629a1f
BLAKE2b-256 ea7f41738e22a54f685a05626cd0c8b8e397bd78b19fda74adedbd436b63765e

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a0780ad58741a377482ba14c700292604a6ea93376431a967b9bab7e019d279c
MD5 b1d31d4c6766abe4532df0f395128f03
BLAKE2b-256 839a7f579033fac462058b9aa6c9f2f7e5ab560ea7da2c89bebe2f1e79dd29af

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d86fcec48571edec725bfddddf8061acd68535086e4651d83c2cfa841855d15
MD5 0f92786b347d66c01ab87feded8dfe1c
BLAKE2b-256 53f4443e214f376ee1fdba076f4b87cc461a3ae07e740dd116d2bbd8fb689e9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickjs_rs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for quickjs_rs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5618b9a105a4a648c07a3cda7a142b0cc49d9b00b8ad58b1903506459fb55c33
MD5 a5f9280e1212602899f1d9411010cdac
BLAKE2b-256 06dcfb9f1f6850b34d5f3e6bb6bf0a14d6e6888ec25306cf33768fe58fdde66b

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickjs_rs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl:

Publisher: release.yml on langchain-ai/quickjs-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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