Skip to content

RuntimeConfig

Configuration for JavaScript runtime instances.

Use this to configure heap limits, execution timeouts, and bootstrap scripts before creating a Runtime.

__init__

__init__(max_heap_size: int | None = None, initial_heap_size: int | None = None, bootstrap: str | None = None, timeout: float | int | None = None, enable_console: bool | None = False, on_console: Callable[[str, list[Any]], Any] | None = None, inspector: InspectorConfig | None = None, snapshot: bytes | None = None, max_serialization_depth: int | None = None, max_serialization_bytes: int | None = None, force_kill_grace: float | int | timedelta | None = None) -> None

Create a new runtime configuration.

Parameters:

Name Type Description Default
max_heap_size int | None

Maximum heap size in bytes

None
initial_heap_size int | None

Initial heap size in bytes

None
bootstrap str | None

JavaScript source code to execute on startup

None
timeout float | int | None

Execution timeout in seconds (float or int)

None
enable_console bool | None

Whether console output reaches the process's stdout/stderr (defaults to False, which stubs console to no-ops). Independent of on_console.

False
on_console Callable[[str, list[Any]], Any] | None

Optional callable invoked as on_console(level, args) for every console.* call from guest JS. level is the method name ("log", "info", "warn", "error", "debug", "trace") and args is that call's argument list. Set it to route console output back to Python; combine with enable_console=True to also keep the process's own console output. Must be synchronous.

None
inspector InspectorConfig | None

Optional inspector configuration enabling Chrome DevTools

None
snapshot bytes | None

Optional V8 startup snapshot bytes

None
max_serialization_depth int | None

Maximum nesting depth when transferring values (default 100). Raising it past roughly 900 is unsafe if you then pass a deep argument from a small-stack thread: the Python-to-JS conversion recurses on the calling thread, and a threading.Thread gets 512 KB on macOS, which peno cannot change. The default has ~9x of headroom on such a thread; see RUNTIME_THREAD_STACK_SIZE in src/runtime/js_value.rs.

None
max_serialization_bytes int | None

Maximum serialized byte size when transferring values

None
force_kill_grace float | int | timedelta | None

How long a blocked caller waits for the runtime to acknowledge a termination before abandoning the runtime thread and raising RuntimeForceKilled. None (the default) waits forever. Only needed for a runtime wedged in a host callback that never returns; runaway JS and never-resolving promises are already bounded. Enabling it costs roughly 10% per synchronous call.

None

on_console property writable

on_console: Callable[[str, list[Any]], Any] | None

The configured console callback, if any.

max_heap_size property writable

max_heap_size: int | None

Maximum heap size in bytes.

initial_heap_size property writable

initial_heap_size: int | None

Initial heap size in bytes.

bootstrap property writable

bootstrap: str | None

Bootstrap script to execute on runtime startup.

timeout property writable

timeout: float | None

Execution timeout in seconds.

enable_console property

enable_console: bool | None

Whether console APIs are enabled inside the runtime.

inspector property writable

inspector: InspectorConfig | None

Inspector configuration if debugging is enabled.

max_serialization_depth property writable

max_serialization_depth: int

Maximum recursion depth allowed when serializing values.

max_serialization_bytes property writable

max_serialization_bytes: int

Maximum byte size allowed when serializing values.

force_kill_grace property writable

force_kill_grace: float | None

Grace period in seconds before abandoning an unresponsive runtime.