Dart hosts the runtime

Tools, event streams, workspaces and child execution in your application.

Loading worker…

Observed output

Events, files and structured errors


Runtime API

final runtime = await MontyRuntime.start(pool: pool, os: files.call,
  externalModules: {'tools': tools});
final value = await runtime.execute('import tools\ntools.add(2, 3)').result;
await runtime.dispose();
await pool.close();

Runtime code lives in lib/src/runtime/, bridge/, extensions/, host/ and os_call/. Core owns the engine, process pool and worker assets.

Engine examples and compatibility → dart_monty_core

Quick Start

One-shot execution

final pool = await Monty.start();
try {
  final result = await pool.withSession((session) => session.feedRun('2 + 2'));
  print(result.dartValue);
} finally { await pool.close(); }

Stateful runtime with extensions

final runtime = await MontyRuntime.start(
  pool: pool, os: OSAccess().call, extensions: [SandboxExtension()]);
await runtime.execute('x = 42').result;
print((await runtime.execute('x + 1').result).dartValue);
await runtime.dispose();

Persistent Python sessions

MontySession supplies feedRun and feedStart/resume. MontyRuntime adds host dispatch, extensions and bridge events. Variables and functions survive across executions. The REPL keeps memory files until Reset.

Interactive REPL · Lifecycle and concurrency

Extensions and filesystems

SandboxExtension supplies sandbox_spawn, sandbox_await, sandbox_gather and sandbox_free. Children have explicit filesystem and external-module grants.

OSAccess supports writable memory files, read-only host mounts and copy-on-write overlays. Host functions register typed schemas and handlers.

Workspace ownership · Extension guide · Filesystem policy

Architecture

dart_monty: lib/src/runtime/, bridge/, extensions/, host/, os_call/
dart_monty_core: engine sessions, worker processes and WASM assets

Native applications communicate with core's worker process. Web applications use js_interop and a Web Worker. MontyRuntime dispatches host callbacks and publishes BridgeEvents as execution suspends and resumes.

Architecture overview

Get Started

Install

dart pub add dart_monty --git-url https://github.com/runyaga/dart_monty.git \
  --git-ref vX.Y.Z-dev.N

Native

Python runs in dart_monty_core's worker process, found by core's discovery or passed to Monty.start as workerLocation.

Web

Python runs in a Web Worker built from core's dart_monty_core_worker.js and dart_monty_core_worker.wasm. Flutter web builds ship them as core's package assets; plain-Dart-web consumers copy them from core's lib/assets/ to web/packages/dart_monty_core/assets/, or anywhere else named by workerLocation:

cp dart_monty_core/lib/assets/dart_monty_core_worker.js web/
cp dart_monty_core/lib/assets/dart_monty_core_worker.wasm web/

Documentation