11 — Budgets¶
Status: budgets and sandboxes are enforced at runtime as of v0.7. CPU/wall/mem/mailbox/spawn counters trap with
MT5009; host and path allowlists trap withMT5015. Seedocs/internals/budgets.md.
A budget { ... } run expr block bounds the resources expr may
consume. Budgets cover CPU time, wall time, memory, mailbox depth,
and more — see spec §16.2 for the full list.
The program¶
fn run_job(input: Bytes) -> Result!RunErr {
budget {
cpu 150ms
wall 2s
mem 128MiB
mb 1k
} run {
job(input)?
}
}
What is interesting¶
- The budget body is a list of
<dimension> <value>entries, one per line. The keys (cpu,wall,mem,mb) are reserved within the budget grammar; the values are duration or size literals. run { ... }introduces the bounded computation. Therunkeyword separates the budget header from the body.1kis a decimal size suffix (=1000), distinct from the binary1KiB(=1024). Seedocs/spec/v0.1-amendments.mdA1.- Budget violations surface as typed errors (
RunErrhere) or trigger supervisor policy — the runtime decides.
For the long form (sandbox ... with { ... } { run ... }), see
examples/18_sandbox.mty and spec §16.1.
Try it¶
Next¶
Continue to 12 — Extern.