Skip to main content

Overview

Monty supports two distinct execution modes:
  1. Simple Execution (run()): Execute code to completion in one call
  2. Iterative Execution (start()/resume()): Pause at external function calls and resume later

Simple Execution with run()

Use run() when your code doesn’t call external functions or when you can provide all external functions upfront.

When to Use run()

  • Pure computations without external dependencies
  • All external functions can be provided synchronously
  • You want the simplest API
  • No need for execution state serialization

Iterative Execution with start() and resume()

Use start() and resume() when you need control over external function calls, want to serialize execution state, or handle async operations.

Basic Pattern

Understanding Execution Flow

Execution State Types

FunctionSnapshot

Execution paused at an external function call:

OsSnapshot

Execution paused for OS operation (filesystem, network):

NameLookupSnapshot

Execution paused to resolve an undefined name:

MontyComplete

Execution finished successfully:

Async External Functions

Monty supports async/await patterns through iterative execution:
See the Async Execution guide for more details on handling concurrent async operations.

Execution State Inspection

With iterative execution, you can inspect and control every external interaction:

Performance Comparison

run() - Simple Execution

  • Startup: ~0.06ms (microseconds)
  • Overhead: Minimal - single function call
  • Use when: Pure computation or all external functions available upfront

start()/resume() - Iterative Execution

  • Startup: ~0.06ms (same as run())
  • Overhead: Small per external call (snapshot creation)
  • Use when: Need control over external calls, serialization, or async handling
Both modes start equally fast. Use run() for simplicity, start()/resume() for control.

Choosing the Right Mode

Use run()

  • Pure computations
  • Sync external functions
  • Simpler code
  • No serialization needed

Use start()/resume()

  • Need execution control
  • Async operations
  • State serialization
  • Security logging
  • Custom error handling

Next Steps

Serialization

Learn how to serialize and restore execution state

Resource Limits

Configure memory, time, and recursion limits