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.ext.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.ext.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.ext.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.ext.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.29.0.tar.gz (364.5 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.29.0-cp312-abi3-win_amd64.whl (53.8 MB view details)

Uploaded CPython 3.12+Windows x86-64

belgie-0.29.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.29.0-cp312-abi3-manylinux_2_28_aarch64.whl (63.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.12+macOS 11.0+ ARM64

belgie-0.29.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.29.0.tar.gz.

File metadata

  • Download URL: belgie-0.29.0.tar.gz
  • Upload date:
  • Size: 364.5 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.29.0.tar.gz
Algorithm Hash digest
SHA256 dd4742253761d292e237a7dca17e9cf96a4d29457c2b5e152565834cb53a9d13
MD5 4c5e2c54d3136e79d00d9e8ff13195c7
BLAKE2b-256 75d6339d0c825e92fb8183fa01da14fe7b7a4d8ab6485feebcf4eb20e6d12adc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.29.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.29.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f2a6da0ab329e7239d39b56e352e6d2d2b45f6a56fc0368d509486d33790c350
MD5 77bfbae83dd6de396f4e005bd65d42b9
BLAKE2b-256 8eb580133f802e561491c1e2d6637b1008a85613c3e35b41ece356191db38eec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.29.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.29.0-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 441ac914a8752eab3f1f1a4864895141f46ff05627e927ff5fa50459bf352522
MD5 22648e4f1e004170856b04c20d575a44
BLAKE2b-256 cfc72b93a62f19df653cd4caecbf684de1d2308fda19e7e8a54d263d1bf4bdd5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.29.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.29.0-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6032f2b2a25cfa5821a030311425a9df8ef5dd5e43ba87076cfca99b7d6a6f83
MD5 33e8b83355b9b8b828f8c2d8ef1d4ba9
BLAKE2b-256 25648d2e4ecf33f144ea8a5bc2d263a69fe9c400f54ec195864a83595c8773e1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.29.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.29.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dff7c16e286c097f1b07acd57db34688164abead2a0c3f63dab21cf6ae0b65c2
MD5 5e4eaa6e1a5b8fb0c68d3e140bc943c6
BLAKE2b-256 da819c741d95a63127d620811f06bb2050efa61589714e9230ca995892908704

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.29.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.29.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d23499d00fc5a9a727286bf52c1edaf173ba3826f3ffea0f9c9bd3041312dcbc
MD5 134e70f22985ad5ced04266c56304a60
BLAKE2b-256 32cd3c7ebdeaa0e3f65abd4f38d43e16925520c8bf5b21bf4f57a1d2c5c37c5d

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