Skip to main content

A Javascript Sandbox for Python, powered by Deno

Project description

Belgie: A Javascript Sandbox for Python, powered by Deno

Belgie lets you run JavaScript and TypeScript from Python. Deno is bundled — you do not need Node.js or Deno on your PATH.

  • Scripts from Python: Run inline or file-based JS/TS with Runtime and Script, sync or async.
  • Inline dependencies: Import npm, JSR, and URL modules directly from JS/TS source.
  • Isolated packages: Use Environment for lockfiles, custom cache/options, local packages, and commands.
  • CLI tools: Run npm binaries (Vite, esbuild, etc.) through Command.
  • Simple data bridge: Pass JSON-safe dicts, lists, and primitives across the boundary.
  • Pydantic AI: Add belgie as a capability so agents get a run_code tool for sandboxed JS/TS.

Installation

uv add belgie
uvx library-skills install  # optional: install the use-belgie skill for Cursor, Codex, Claude, etc.

Quick Start

import asyncio

from belgie import Runtime, Script

script = Script[[str], str](
    """
import camelcase from "npm:camelcase@8.0.0";

export default function run(input: string): string {
  return camelcase(input);
}
"""
)

async def main() -> None:
    async with Runtime() as run:
        print(await run(script)("foo-bar"))  # prints: fooBar

asyncio.run(main())

Pydantic AI

belgie.capabilities.pydantic_ai.BelgieCapability is a Pydantic AI capability that gives the agent a run_code tool. The model writes a belgie.Script module and Belgie runs it in the embedded Deno sandbox.

Install the optional extra with uv add "belgie[pydantic-ai]". Set OPENAI_API_KEY, then:

from pydantic_ai import Agent

from belgie.capabilities.pydantic_ai import BelgieCapability

agent = Agent("openai:gpt-5", capabilities=[BelgieCapability()])

result = agent.run_sync(
    "Use run_code with a TypeScript belgie.Script module that imports npm:camelcase "
    "and returns camelCase('foo-bar').",
)
print(result.output)

See the full runnable project in examples/pydantic-ai.

LangChain

belgie.capabilities.langchain.BelgieMiddleware is a LangChain agent middleware that gives the agent a run_code tool. The model writes a belgie.Script module and Belgie runs it in the embedded Deno sandbox.

Install the optional extra with uv add "belgie[langchain]". Set OPENAI_API_KEY, then:

from langchain.agents import create_agent

from belgie.capabilities.langchain import BelgieMiddleware

agent = create_agent(
    model="openai:gpt-5",
    tools=[],
    middleware=[BelgieMiddleware()],
    system_prompt="You can execute JS/TS in a Deno sandbox with run_code.",
)

result = agent.invoke(
    {
        "messages": [
            (
                "user",
                "Use run_code with a TypeScript belgie.Script module that imports npm:camelcase "
                "and returns camelCase('foo-bar').",
            ),
        ],
    },
)
print(result["messages"][-1].content)

See the full runnable project in examples/langchain.

Examples

Want to learn more about Belgie's features? The examples below are small, runnable projects — each one focuses on a single capability.

  • simple: Async Runtime with a TypeScript file on disk.
  • inline-deps: Direct npm:, jsr:, and URL imports in a script.
  • jsr-deps: JSR packages declared through an explicit Environment.
  • environment: Sync and async Environment setup with path.
  • commands: npm package binaries via Runtime and Command.
  • pydantic-ai: Pydantic AI agent with the BelgieCapability capability and run_code tool.

For deeper integration guidance, optionally install the use-belgie skill with uvx library-skills install.

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

belgie-0.28.0.tar.gz (364.6 kB view details)

Uploaded Source

Built Distributions

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

belgie-0.28.0-cp312-abi3-win_amd64.whl (53.8 MB view details)

Uploaded CPython 3.12+Windows x86-64

belgie-0.28.0-cp312-abi3-manylinux_2_28_x86_64.whl (61.4 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

belgie-0.28.0-cp312-abi3-manylinux_2_28_aarch64.whl (63.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

belgie-0.28.0-cp312-abi3-macosx_11_0_arm64.whl (55.9 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

belgie-0.28.0-cp312-abi3-macosx_10_12_x86_64.whl (57.9 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file belgie-0.28.0.tar.gz.

File metadata

  • Download URL: belgie-0.28.0.tar.gz
  • Upload date:
  • Size: 364.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.28.0.tar.gz
Algorithm Hash digest
SHA256 8737410cb5c7024fe4380c2f35acec810ac8badc090029925a199aa98ec6b809
MD5 daed8562baf059d2dcd65c67d24b27b2
BLAKE2b-256 d56e1ec9efd8623b45e05e4ab62a4fca534335e8afc6b2c56c72d3ebc2c43cc3

See more details on using hashes here.

File details

Details for the file belgie-0.28.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: belgie-0.28.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 53.8 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.28.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5603b8699c52af7ef00bc59c9432be3cbe1406be61f2d830d4ff6aadcbdbd227
MD5 5bd3b6dfe5241289a8571cd6229df756
BLAKE2b-256 a81e17f7df035e25e52724e4aa1e5d51cfe64d8d7bea2d99c2f691de50b9a157

See more details on using hashes here.

File details

Details for the file belgie-0.28.0-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: belgie-0.28.0-cp312-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 61.4 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.28.0-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 54a790c150ae426d114589fcecaa0cfabb41d5c1ff04f31f7797679ac89d3082
MD5 8e203b68cc02a22ea916a50550904b3f
BLAKE2b-256 823b68707423b7dff250be7e883a097da321ddd30ae5e67c5f484f117e9f222e

See more details on using hashes here.

File details

Details for the file belgie-0.28.0-cp312-abi3-manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: belgie-0.28.0-cp312-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 63.1 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.28.0-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 047eca5d20ae8c24c37f26535868a94308360fe9e8132cd70461b9937915fce3
MD5 5c90d140547f8e1940838b7d82a5b4ea
BLAKE2b-256 bd69d59b3fe4aa5c92bbde6bc6599f8b09a9060c68ac3ce3c508ea0b8bff3e2f

See more details on using hashes here.

File details

Details for the file belgie-0.28.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: belgie-0.28.0-cp312-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 55.9 MB
  • Tags: CPython 3.12+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.28.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a74edba739f6e100aafe4725ed636202d9fd17bbc5b010a73fab0ea3e60ed840
MD5 1c404effdb2db4f5276512422c0b9b98
BLAKE2b-256 2904cd9b5e1c0ebcafd7136b345e135736d00150fb33d20e19b0b92a17e584ed

See more details on using hashes here.

File details

Details for the file belgie-0.28.0-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: belgie-0.28.0-cp312-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 57.9 MB
  • Tags: CPython 3.12+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.28.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 daa946af0b631157e4cda2bb873e157cc04cfe7bf584f41713cbc4efbe1c533a
MD5 b2e756dc708e9b2aec2fef20aba16136
BLAKE2b-256 bd1dad8d71ce652364f543db69291be862f6b8801a2274054f2ac5fb339452e3

See more details on using hashes here.

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