On this page

0079. Sandbox limits: pure entry, heap and output caps

Context

Fuel bounds interpreter work but not allocation: repeated fresh-buffer growth can exhaust host memory before fuel runs out. Generator functions have no capabilities by type, but hand-built IR must not accidentally perform platform effects. The interpreter also needs an entry point that executes a selected function and returns its value, rather than entering main and discarding the result.

Decision

Add interp::run_pure(&Program, FuncId, Limits) -> PureOutcome. It runs on its own scoped worker thread, as interpret_on_stdout does. The zero-argument synthetic entry returns result<str, str>; either string payload is transferred back as an owned Rust String, not as interpreter storage.

Limits includes optional cumulative heap accounting. Charge fresh buffer allocation and growth before growing, using checked size arithmetic; do not charge views. This includes field/frame buffers, materialized view vectors, iterator carrier records and temporary byte-key copies. Index/range storage and numeric formatting use conservative allowances. Exhaustion traps with out of memory; there are no refunds. This bounds charged storage, not exact RSS.

Generator constants are fixed, with no manifest override:

Limit Value Rule
Fuel GEN_FUEL = 50_000_000 ADR-0017's unit: function entries and loop-head entries
Heap GEN_HEAP_BYTES = 256 MiB Cumulative fresh buffer allocation/growth
Output GEN_OUTPUT_BYTES = 16 MiB Maximum returned string, for either ok or err

When Machine.sandboxed is true, Rvalue::Platform, StmtKind::Print and exit are rejected as compiler-bug ToolError (exit 3). Ordinary interpreter execution remains unchanged; with heap limits absent it performs no heap sizing/accounting work.

Alternatives considered

Consequences

Pure generator evaluation is bounded by deterministic fuel, charged heap growth and returned-output size. All fresh-buffer growth paths must participate in accounting; views remain free. This amends ADR-0017 only for the sandbox API: its fuel unit and ordinary interpreter behavior remain unchanged. ADR-0074 ceilings remain declared intent, not a security boundary.