{"id":36429785,"url":"https://github.com/imfing/jsrun","last_synced_at":"2026-01-20T07:34:16.810Z","repository":{"id":328312153,"uuid":"1087656445","full_name":"imfing/jsrun","owner":"imfing","description":"Modern JavaScript runtime in Python, powered by V8 and bridged by Rust","archived":false,"fork":false,"pushed_at":"2025-11-17T17:37:58.000Z","size":418,"stargazers_count":35,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-31T08:43:06.932Z","etag":null,"topics":["agents","javascript","llm","pyo3","python","rust","sandbox","v8"],"latest_commit_sha":null,"homepage":"https://imfing.github.io/jsrun/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imfing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing/architecture.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-01T11:18:39.000Z","updated_at":"2025-12-26T10:01:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/imfing/jsrun","commit_stats":null,"previous_names":["imfing/jsrun"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/imfing/jsrun","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imfing%2Fjsrun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imfing%2Fjsrun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imfing%2Fjsrun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imfing%2Fjsrun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imfing","download_url":"https://codeload.github.com/imfing/jsrun/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imfing%2Fjsrun/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28535274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agents","javascript","llm","pyo3","python","rust","sandbox","v8"],"created_at":"2026-01-11T19:00:29.343Z","updated_at":"2026-01-20T07:34:16.802Z","avatar_url":"https://github.com/imfing.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/imfing/jsrun\"\u003e\n    \u003cpicture\u003e\n      \u003cimg alt=\"jsrun\" width=\"100\" src=\"docs/assets/logo.png\"  \u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n\n# jsrun\n\n**Modern JavaScript runtime in Python**\n\nSeamlessly run JavaScript next to Python with secure isolation, powered by V8 and bridged with Rust\n\n\u003cbr /\u003e\n\n[![CI](https://github.com/imfing/jsrun/actions/workflows/CI.yml/badge.svg)][workflows-ci]\n[![PyPI](https://img.shields.io/pypi/v/jsrun.svg)][jsrun-pypi]\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\n\u003cp align=\"center\"\u003e\n\n  \u003ca href=\"https://imfing.github.io/jsrun/\"\u003e\u003cstrong\u003eDocumentation\u003c/strong\u003e\u003c/a\u003e\n  ·\n  \u003ca href=\"https://github.com/imfing/jsrun/tree/main/examples\"\u003e\u003cstrong\u003eExamples\u003c/strong\u003e\u003c/a\u003e\n  ·\n  \u003ca href=\"https://github.com/imfing/jsrun/issues\"\u003e\u003cstrong\u003eIssues\u003c/strong\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003c/div\u003e\n\n`jsrun` is a Python library that embeds the [V8][v8] JavaScript engine with Rust ([PyO3][pyo3]). Run trusted or user-provided JavaScript alongside Python, bind Python objects into JavaScript in an isolated environment:\n\n```python\nimport jsrun\n\nresult = jsrun.eval(\"2 + 2\")\nprint(result)  # 4\n\n# Bind Python function\njsrun.bind_function(\"add\", lambda a, b: a + b)\nprint(jsrun.eval(\"add(2, 3)\"))  # 5\n```\n\n## Highlights\n\n- **Fast V8 core** – the JavaScript engine used by Chrome and Node.js, bridged via Rust and PyO3\n- **Async-first APIs** – run async JavaScript without blocking Python code\n- **Extensible bindings** – expose Python functions/objects to JavaScript\n- **Secure defaults** – runtimes start with zero I/O, isolated V8 isolates per thread, and configurable heap/time limits\n- **Module \u0026 WASM support** – load ES modules with custom resolvers and execute WebAssembly directly\n\n## Get Started\n\nTo get started, install it from PyPI (Python 3.10+ and macOS/Linux are required):\n\n```bash\npip install jsrun  # or uv pip install jsrun\n```\n\n\u003e **Note**: `jsrun` is under development. Expect breaking changes between minor versions.\n\nQuick Example\n\n```python\nimport jsrun\n\n# Simple expression\nprint(jsrun.eval(\"Math.sqrt(25)\"))  # 5\n\n# Share Python function with JavaScript\njsrun.bind_function(\"add\", lambda a, b: a + b)\nprint(jsrun.eval(\"add(3, 4)\"))  # 7\n```\n\nNeed full control? Use the [`Runtime`](https://imfing.github.io/jsrun/api/runtime) class to configure heap/time limits, module loaders, and lifecycle management.\n\n```python\nfrom jsrun import Runtime\n\nconfig = RuntimeConfig(max_heap_size=10 * 1024 * 1024)  # 10MB limit\n\nwith Runtime(config) as runtime:\n    print(runtime.eval(\"42\"))  # 42\n```\n\n## Use Cases\n\n`jsrun` is designed for modern Python applications that need embedded JavaScript:\n\n- **[AI agents](https://imfing.github.io/jsrun/use-cases/agents/)** – execute LLM generated JavaScript in isolated sandboxes with memory/time limits\n- **[Workflow runners](https://imfing.github.io/jsrun/use-cases/workflows/)** – let users upload JavaScript automations backed by your Python host\n- **[Serverless / plugin runtimes](https://imfing.github.io/jsrun/use-cases/serverless/)** – spin up per-request V8 isolates with custom APIs\n- **[Data playgrounds](https://imfing.github.io/jsrun/use-cases/playground/)** – build notebooks or playgrounds that mix Python data and JS visualizations\n- **[JavaScript libraries](https://github.com/imfing/jsrun/blob/main/examples/markdown_parser.py)** – use JavaScript packages like [marked.js][marked-js] directly in Python without Node.js\n\n### Example: Code execution sandbox for AI Agent\n\nOne 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.\n\nThis example shows how to create a [Pydantic AI](https://ai.pydantic.dev/) agent that can execute JavaScript code in a sandboxed V8 runtime with heap limits and timeouts:\n\n```python\nimport asyncio\n\nfrom jsrun import JavaScriptError, Runtime, RuntimeConfig\nfrom pydantic_ai import Agent, RunContext\n\n# Define the agent with code execution tool\nagent = Agent(\n    \"openai:gpt-5-mini\",\n    system_prompt=\"\"\"You are a helpful assistant that can execute JavaScript code.\n    When users ask you to perform calculations or data transformations,\n    you can write and execute JavaScript code to get accurate results.\n    Always explain what the code does before showing the result.\"\"\",\n)\n\n\n@agent.tool\nasync def execute_javascript(ctx: RunContext, code: str) -\u003e str:\n    \"\"\"\n    Execute JavaScript code in a sandboxed environment.\n\n    Args:\n        code: The JavaScript code to execute\n\n    Returns:\n        The result of the code execution as a string\n    \"\"\"\n    # Log or audit the code being executed (for observability)\n    print(f\"[Executing JavaScript code] '{code}'\")\n\n    try:\n        # Create a runtime with 10MB heap limit\n        config = RuntimeConfig(max_heap_size=10 * 1024 * 1024)\n\n        with Runtime(config) as runtime:\n            result = await runtime.eval_async(code, timeout=5.0)\n            print(f\"[Execution result] {result}\")\n            return f\"Result: {result}\"\n    except TimeoutError:\n        return \"Error: Code execution timed out (exceeded 5 seconds)\"\n    except JavaScriptError as e:\n        return f\"JavaScript Error: {e}\"\n    except Exception as e:\n        return f\"Execution Error: {e}\"\n\n\nasync def main():\n    result = await agent.run(\"Calculate the sum of squares from 1 to 100\")\n    print(f\"AGENT OUTPUT: {result.output}\")\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### Example: Using JavaScript libraries in Python\n\nYou can load supported JavaScript libraries directly from CDNs and use them in Python without Node.js:\n\n```python\nimport requests, jsrun\n\nresponse = requests.get(\"https://unpkg.com/lodash@4/lodash.min.js\")\njsrun.eval(response.text)\n\n# Use lodash functions\nresult = jsrun.eval(\"_.chunk(['a', 'b', 'c', 'd'], 2)\")\nprint(result)  # [['a', 'b'], ['c', 'd']]\n\n# Bind Python data to JavaScript\njsrun.bind_object(\"numbers\", {\"data\": [1, 5, 10, 15, 20, 25]})\n\nresult = jsrun.eval(\"_.filter(numbers.data, n =\u003e n \u003e= 10)\")\nprint(result)  # [10, 15, 20, 25]\n```\n\nExplore more in [Use Cases](https://imfing.github.io/jsrun/use-cases/playground/) and [Examples](https://github.com/imfing/jsrun/tree/main/examples)\n\n## Documentation\n\n- [Quick Start](https://imfing.github.io/jsrun/quickstart)\n- [Concepts](https://imfing.github.io/jsrun/concepts/runtime): runtimes, type conversion, resource controls\n- [Guides](https://imfing.github.io/jsrun/guides/bindings): binding functions, module loading\n- [API reference](https://imfing.github.io/jsrun/api/jsrun/)\n\n\n[v8]: https://v8.dev\n[pyo3]: https://pyo3.rs/\n[jsrun-pypi]: https://pypi.org/project/jsrun/\n[workflows-ci]: https://github.com/imfing/jsrun/actions/workflows/CI.yml\n[marked-js]: https://github.com/markedjs/marked\n","funding_links":[],"categories":["Utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimfing%2Fjsrun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimfing%2Fjsrun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimfing%2Fjsrun/lists"}