@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
66 lines • 3.57 kB
TypeScript
import type { Context } from '../../../commands/config.ts';
import { PythonRuntime } from '../base.ts';
import type { OutputFn, Program, RunResult } from '../../types.ts';
import { type RuntimeOptions } from '../../config.ts';
import type { MontyConfig } from './config.ts';
import { MontyExecution } from './execution.ts';
/**
* Run Python code on the Monty sandboxed interpreter (`@pydantic/monty`).
*
* Code executes in a crash-isolated Monty worker: no host filesystem,
* environment, or network access. `pathlib` I/O is serviced through the
* workspace bridge, so the code sees the workspace mounts and nothing
* else, and the run's env is readable both ways python's monty spells
* it: `os.getenv` and `os.environ` (a dict copy, so the two hosts run
* the same program). Command-line arguments are exposed as the
* `argv` global (`argv[0]` is the script name) and piped input as the
* `stdin` global (bytes, None when nothing was piped). The builtin
* `open()` is bridged (@pydantic/monty 0.0.21 carries a
* `MontyFileHandle` back from the `os` callback), and a path no mount
* serves is refused, as on the python host: the guest sees the
* workspace and nothing else. `Path.stat()` is bridged too, as a class instance carrying
* CPython's `stat_result` fields; only its sequence half (`st[6]`,
* `len(st)`) is the python host's alone. Monty implements a Python
* subset; host-only features (`sys.stdin`, `sys.argv`, third-party
* imports) are unavailable; supported stdlib modules are listed under
* "Python subset" in docs/home/setup/runtime/monty.mdx. The parser
* refuses class inheritance, method decorators and `yield` — use the
* pyodide runtime for a program that needs those.
*
* `externalLookup` is the host functions the code may call by name, empty
* unless the one who built the runtime hands it some, as a policy does for
* its own programs. `shared` runs it on the process's shared worker pool; a
* policy's own runtime keeps a pool of its own, since its programs judge the
* reads runs on the shared pool make and must not wait behind them.
*/
export declare class MontyRuntime extends PythonRuntime<MontyExecution> {
readonly name = "monty";
protected readonly versionSuffix = " (monty)";
readonly reach = "workspace";
readonly filesystem: readonly ["read", "write", "list", "stat"];
readonly runsModules = false;
config: MontyConfig;
externalLookup: Readonly<Record<string, (...args: never[]) => unknown>>;
shared: boolean;
private readonly maxMemory;
constructor(options?: RuntimeOptions<MontyConfig>);
protected openEngine(): Promise<MontyExecution>;
protected closeEngine(engine: MontyExecution): Promise<void>;
/**
* Run one program, reporting any switch this engine cannot honor.
*
* Monty implements a Python subset with no `compile`, no `warnings`
* and no `sys.path`, so the interpreter-init switches have nothing to
* act on here even though every real-CPython engine honors them. The
* notice rides on stderr, ahead of what the program writes there, and
* the program's own exit code stands.
*
* @param engine the install's worker pool.
* @param program the source and argv to run.
* @param ctx the run's context.
* @param output receives stdout as it is printed.
* @param errors receives stderr as it is printed.
*/
interpret(engine: MontyExecution, program: Program, ctx: Context, output?: OutputFn, errors?: OutputFn): Promise<RunResult>;
}
//# sourceMappingURL=runtime.d.ts.map