@capsule-run/adapter
v0.1.0
Published
Capsule adapter for typescript applications
Readme
Capsule TypeScript Adapter
Execute Python and JavaScript code securely inside Capsule sandboxes from your TypeScript/JavaScript applications.
Installation
npm install @capsule-run/adapterUsage
Execute Python Code
import { executePython } from '@capsule-run/adapter';
const result = await executePython(`
print("Hello from Python!")
x = 5 + 3
x * 2
`);
console.log(result); // "Hello from Python!\n16"Execute JavaScript Code
import { executeJavaScript } from '@capsule-run/adapter';
const result = await executeJavaScript(`
console.log("Hello from JavaScript!");
const x = 5 + 3;
x * 2;
`);
console.log(result); // "Hello from JavaScript!\n16"How It Works
The adapter compiles Python and JavaScript sandboxes into WebAssembly modules during the build step. When you call executePython() or executeJavaScript(), the adapter invokes these pre-built sandboxes using Capsule's runner with the code you provide.
Building from Source
npm install
npm run buildThis will:
- Compile the Python sandbox (
src/python_sandbox.py) todist/sandboxes/python_sandbox.wasm - Compile the JavaScript sandbox (
src/js_sandbox.ts) todist/sandboxes/js_sandbox.wasm - Build the TypeScript adapter code to
dist/index.js
