Skip to main content
jsrun

jsrun

Modern JavaScript runtime in Python

Seamlessly run JavaScript next to Python with secure isolation, powered by V8 and bridged with Rust


CI PyPI License

Documentation · Examples · Issues

jsrun is a Python library that embeds the V8 JavaScript engine with Rust (PyO3). Run trusted or user-provided JavaScript alongside Python, bind Python objects into JavaScript in an isolated environment:

import jsrun

result = jsrun.eval("2 + 2")
print(result)  # 4

# Bind Python function
jsrun.bind_function("add", lambda a, b: a + b)
print(jsrun.eval("add(2, 3)"))  # 5

Highlights

  • Fast V8 core – the JavaScript engine used by Chrome and Node.js, bridged via Rust and PyO3
  • Async-first APIs – run async JavaScript without blocking Python code
  • Extensible bindings – expose Python functions/objects to JavaScript
  • Secure defaults – runtimes start with zero I/O, separate V8 isolates per thread, and configurable heap/time limits
  • Module & WASM support – load ES modules with custom resolvers and execute WebAssembly directly

Get Started

To get started, install it from PyPI (Python 3.10+ and macOS/Linux are required):

pip install jsrun  # or uv pip install jsrun

Note: jsrun is experimental. Expect breaking changes between versions.

Quick Example

import jsrun

# Simple expression
print(jsrun.eval("Math.sqrt(25)"))  # 5

# Share Python function with JavaScript
jsrun.bind_function("add", lambda a, b: a + b)
print(jsrun.eval("add(3, 4)"))  # 7

Need full control? Use the Runtime class to configure heap/time limits, module loaders, and lifecycle management.

from jsrun import Runtime, RuntimeConfig

config = RuntimeConfig(max_heap_size=10 * 1024 * 1024)  # 10MB limit

with Runtime(config) as runtime:
    print(runtime.eval("42"))  # 42

Use Cases

jsrun is designed for modern Python applications that need embedded JavaScript:

Example: Code execution sandbox for AI Agent

One of the most compelling use cases for jsrun is building safe execution environments for AI agents. When LLMs generate code, you need a way to run it securely with strict resource limits and isolation.

This example shows how to create a Pydantic AI agent that can execute JavaScript code in a sandboxed V8 runtime with heap limits and timeouts:

import asyncio

from jsrun import JavaScriptError, Runtime, RuntimeConfig
from pydantic_ai import Agent, RunContext

# Define the agent with code execution tool
agent = Agent(
    "openai:gpt-5-mini",
    system_prompt="""You are a helpful assistant that can execute JavaScript code.
    When users ask you to perform calculations or data transformations,
    you can write and execute JavaScript code to get accurate results.
    Always explain what the code does before showing the result.""",
)


@agent.tool
async def execute_javascript(ctx: RunContext, code: str) -> str:
    """
    Execute JavaScript code in a sandboxed environment.

    Args:
        code: The JavaScript code to execute

    Returns:
        The result of the code execution as a string
    """
    # Log or audit the code being executed (for observability)
    print(f"[Executing JavaScript code] '{code}'")

    try:
        # Create a runtime with 10MB heap limit
        config = RuntimeConfig(max_heap_size=10 * 1024 * 1024)

        with Runtime(config) as runtime:
            result = await runtime.eval_async(code, timeout=5.0)
            print(f"[Execution result] {result}")
            return f"Result: {result}"
    except TimeoutError:
        return "Error: Code execution timed out (exceeded 5 seconds)"
    except JavaScriptError as e:
        return f"JavaScript Error: {e}"
    except Exception as e:
        return f"Execution Error: {e}"


async def main():
    result = await agent.run("Calculate the sum of squares from 1 to 100")
    print(f"AGENT OUTPUT: {result.output}")


if __name__ == "__main__":
    asyncio.run(main())

Example: Using JavaScript libraries in Python

You can load supported JavaScript libraries directly from CDNs and use them in Python without Node.js:

import requests, jsrun

response = requests.get("https://unpkg.com/lodash@4/lodash.min.js")
jsrun.eval(response.text)

# Use lodash functions
result = jsrun.eval("_.chunk(['a', 'b', 'c', 'd'], 2)")
print(result)  # [['a', 'b'], ['c', 'd']]

# Bind Python data to JavaScript
jsrun.bind_object("numbers", {"data": [1, 5, 10, 15, 20, 25]})

result = jsrun.eval("_.filter(numbers.data, n => n >= 10)")
print(result)  # [10, 15, 20, 25]

Explore more in Use Cases and Examples

Documentation

Metadata

Release files for jsrun 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsrun 0.3.0
File Size Uploaded
jsrun-0.3.0.tar.gz 286.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for jsrun 0.3.0
File
jsrun-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
jsrun-0.3.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
jsrun-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
jsrun-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
jsrun-0.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details

Total release size: 112.7 MB

Release files / jsrun-0.3.0.tar.gz

Download URL jsrun-0.3.0.tar.gz
Size 286.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4fd0f6999cec91db7a811c8958967544a935a5c27376047e26fb8947e469c503
BLAKE2b-256 checksum
How to use checksums
ee57a5d6dc881bd402dcad2a15a2abc75def47140758888f2ed29a288129d912
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / jsrun-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL jsrun-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 23.9 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
cc4dea041a56d4279983b5689b73b7a03d1f283c0a716cb4b0831280d0b2fc97
BLAKE2b-256 checksum
How to use checksums
d75ec09e91dd06428da4c28bd693fbf83620b55e4ace32d212dcb17e04beb0bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / jsrun-0.3.0-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL jsrun-0.3.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 23.4 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
a53c3905b9f06a2b3b02a5453b948724e86f2372abdf878155fbbac6aafcf21d
BLAKE2b-256 checksum
How to use checksums
762d2ad89e2c48b74a74d6395bc0201339c53c4e4db53df5216337fda2373362
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / jsrun-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL jsrun-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 21.9 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
bcde8ac39f220590b4ccb6026e97d81cb01151857cc5737f21bfdd5d712f5fb5
BLAKE2b-256 checksum
How to use checksums
d668931694a2ae2acaa7a21731d9a157a20612138cab59e22a4e973ca50fbb2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / jsrun-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL jsrun-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 23.4 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
53820305ee8a582485750fa4c3a451aff2d0aab282b773e49b804bf819392108
BLAKE2b-256 checksum
How to use checksums
db54172b67aeff90c4e3ac7087458b9190920fa0aacfee2c3dae4a80639e8cd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / jsrun-0.3.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL jsrun-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Size 19.8 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c7d39feb7ef7a7d8d9a916f476d21bba7e90a85dfff36a201388e3788df34f97
BLAKE2b-256 checksum
How to use checksums
0e2b3d65eabba13e5cb58366d8c3a3bd8d506ce73f4bdb0b866a1784bf981c2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files

0.2.0

4 release files

0.1.0

18 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page