Skip to main content

Modern embedded JavaScript runtime for Python powered by V8 and Rust.

Project description

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, isolated 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 under development. Expect breaking changes between minor 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

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 safety limits
        config = RuntimeConfig(
            max_heap_size=10 * 1024 * 1024,  # 10MB heap limit
        )

        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())

Explore more in Use Cases and Examples

Documentation

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

jsrun-0.1.0.tar.gz (231.9 kB view details)

Uploaded Source

Built Distributions

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

jsrun-0.1.0-pp311-pypy311_pp73-manylinux_2_28_aarch64.whl (21.9 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

jsrun-0.1.0-cp314-cp314t-manylinux_2_28_aarch64.whl (21.9 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ ARM64

jsrun-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl (22.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

jsrun-0.1.0-cp314-cp314-manylinux_2_28_aarch64.whl (21.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

jsrun-0.1.0-cp314-cp314-macosx_11_0_arm64.whl (18.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

jsrun-0.1.0-cp313-cp313t-manylinux_2_28_aarch64.whl (21.9 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.28+ ARM64

jsrun-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl (22.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

jsrun-0.1.0-cp313-cp313-manylinux_2_28_aarch64.whl (21.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

jsrun-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (18.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

jsrun-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (22.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

jsrun-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl (21.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

jsrun-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (18.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

jsrun-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (22.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

jsrun-0.1.0-cp311-cp311-manylinux_2_28_aarch64.whl (21.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

jsrun-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (18.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

jsrun-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (22.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

jsrun-0.1.0-cp310-cp310-manylinux_2_28_aarch64.whl (21.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

File details

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

File metadata

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

File hashes

Hashes for jsrun-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b363e2cc9666859e2c3b46d97b7463c17c992c6f49a3d8c00d10eee4f040b9ae
MD5 c859f7e52b3960c65918dcac297bca28
BLAKE2b-256 8a995ed5e4934a2924a7697375ac9de18db9b2745b0fb7c80c31054c67f9e8e2

See more details on using hashes here.

Provenance

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

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-pp311-pypy311_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-pp311-pypy311_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 778465d75aae17704d82945488cea7b5a034ba9a086f9989c8298bb2d726daf0
MD5 bd11b52b961013ce17e8c4eec1ff8504
BLAKE2b-256 3c659776536278b3b3e0c4e32e59bd3d2da02b4bf18f3d4ea4731402accabdc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-pp311-pypy311_pp73-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp314-cp314t-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp314-cp314t-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a55b345c911a2a991cf3a000356c0db8c240e4c2dbb2fccd43209cfb5e68bbac
MD5 c546b63ce94b775ed0b150fa2abe4da0
BLAKE2b-256 20f527ff0dfcfc8556ccc2fb83d6407586383da40b8d602095f886013b5d0d28

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp314-cp314t-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a524f336e1a21545e584586e48714400cbbe975ebb09960fae6290211bc3cce0
MD5 23edc243fceed4e5f6aabe85ecc9dd90
BLAKE2b-256 6d66f9e6317fd538197f5ebf7a28e658f7e199b5fdd5d5daab542df367131eb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp314-cp314-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a3f0299c6e38c043108e3ed6796195ac0bcb2a195671602c2f76f7914a4906c5
MD5 12584edb80f601e1b8272282e21a1762
BLAKE2b-256 ce30b33363bc2f112df4b7ddbfb8656a7cdf8a523966fd1ba24362251ce521b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp314-cp314-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32cc4e213034fa7d2f66f2969340ab6951b5300fd237cb19b59f8b2843f00588
MD5 16e566da5bf422d3fea6a55b21946617
BLAKE2b-256 bc483147fa3a3f090c4987bac834b4c5cfe55c8f0b90a47465437486c93014c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp313-cp313t-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp313-cp313t-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2d2c0ed33a0222f83eddf7d436d702ca2a6c10d5c71e245151c36423977c1ba3
MD5 de26e026052729760fc3ed39994a8de8
BLAKE2b-256 f6d6f62ffdb870c44e1b1f0a4b9cc711794fbec3e0433f91b87d413804de0c94

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp313-cp313t-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c213b0a53ba00ef29f69d9abd6bb471803e5859259ea560ea36f966a7122d258
MD5 b429420711e98048103ea1c3f5cd8aa3
BLAKE2b-256 9129583cc7fdf6eb9043f93e91c3cee9339d0c306b4475b213759e420b3c3466

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c763e35a5cc2fdbf3ccbf4725c28e59aa45c7183962bd01dfc24cf3589f5e0e2
MD5 0e72d4e1a68452499f4f96671b79a123
BLAKE2b-256 bfd4d1b2b1a9a145b7a0276d6e10861cd86a08b8816087f6057eeed7cb998cbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp313-cp313-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

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

File metadata

File hashes

Hashes for jsrun-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ab8ffa6a0f70490bc2381dcc1db7be41b8e92918d52354723851a71789248fe8
MD5 ba15fe589cdef105ddfe6437faed2fcf
BLAKE2b-256 ba919f7ef3e69e0b0e72e40cb61edaeac57b7b4c06110fcd26abacd73db129d9

See more details on using hashes here.

Provenance

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

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d88e61dca605ccbab7fb9cc3c6ea46c67ad349b9a0eaaa1265db97d281c936e5
MD5 1cc641a22191a316cff46c83aa357e3d
BLAKE2b-256 0e17a61051555d4c748a7c819fba7400265b9fb482554d0f91ea047c773eccc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b6af73e05e932d95758e9cd219900b3ab8ea144f0cede6f820672ae6692bc7f4
MD5 f54d8a5b548424a2b7e102fd1751896c
BLAKE2b-256 7a3d1401fee4b4de4840e4e2621342b15a4f0c87b91afc73edcb8e37d8a2920f

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

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

File metadata

File hashes

Hashes for jsrun-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 054a66dd13e74d320b48f927128e3db06ae1de909dc917e6cb1071ea8108ee56
MD5 4fa4639c3339d7dca3880dd8607e2262
BLAKE2b-256 f5bd5691ed028bfd8684378ff0dffefec50cd53ce35092a942c0ce88d3494ad0

See more details on using hashes here.

Provenance

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

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cc9be776507c0af63d8720ff0a9f6b0955a99239afcba6686237f1e8e11759ce
MD5 46d2f65e99b3a090cf09227dc7fa08bf
BLAKE2b-256 69afaaedc3026df193089aeb5c213224e7d63e2553b6c2244786b8f643d91791

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 42b6975d5c5e38f1a466f2f25f680838efdbca56d60d302267902b4cadce3310
MD5 17cf988e68cbc2a877cfd3df614aab75
BLAKE2b-256 ec8fcd017f464dbb72722be03107dc7fae6e10359fd73191751240cafb48a05f

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp311-cp311-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

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

File metadata

File hashes

Hashes for jsrun-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e221f0ef747ea2966706e66c9134f6204b8c2976f37c60df5a21c3eb30e8565
MD5 6d2efd8bf20df8df6cfb578113f9aaad
BLAKE2b-256 12f247a920807a8f32ca8e6deac77d3243f57af9b1c967535b9621da6d0886d6

See more details on using hashes here.

Provenance

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

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 20d37caba647a63f9e5067bb499c0e1a1ab7f814278ea6cef57d77c552f1e188
MD5 9414a9fad3c3aee0898f01673eb5dbf3
BLAKE2b-256 4c33ee914bd53a5e0d25eddb0e3aad133d0259ea2e7c47725cb144065b4b4b99

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: CI.yml on imfing/jsrun

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

File details

Details for the file jsrun-0.1.0-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for jsrun-0.1.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 214f4e23b99f0d26d43ddc75ba5c992d99a0d1dcb2f0566d753cd2bab724b52d
MD5 962a0f7ef89094300f860bd9e9791e75
BLAKE2b-256 b59afd4c633fa09d9c01b881543c27e283039ca05c300000fe65ba9ac6902d38

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsrun-0.1.0-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on imfing/jsrun

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