engine.solvers.sandboxes
engine.solvers.sandboxes
Agent-sandbox solvers: the cost of an isolation envelope (added 2026-10-20).
Domain implementations behind mlsysim.solvers. Each model is arithmetic on stated per-call, per-byte, or per-lease inputs: the system-call tax each envelope pays, setup paid per call or once per trajectory, workspace provisioning by copy or copy-on-write, and a warm pool sized by Little’s law and a Poisson reserve. None models queueing inside a host, restore contention, or a particular hypervisor.
Classes
| Name | Description |
|---|---|
| EnvelopeAmortizationModel | Setup paid on every call against once per trajectory, under equal useful work. |
| SandboxPoolReserveModel | A warm sandbox pool under steady Poisson arrivals. |
| SyscallTaxModel | The added time of calls ordinary system calls under each envelope. |
| WorkspaceProvisioningModel | Bytes to provision workspaces by full copy or copy-on-write, and the |
EnvelopeAmortizationModel
engine.solvers.sandboxes.EnvelopeAmortizationModel()Setup paid on every call against once per trajectory, under equal useful work.
Fresh per call: N (T_setup + W); retained: T_setup + N W. Setup is T_setup / (T_setup + W) of a fresh call, and holding it to a share phi needs W >= T_setup (1 - phi) / phi. Serialized, no overlap.
Methods
| Name | Description |
|---|---|
| solve | Compare fresh and retained envelope setup costs. |
solve
engine.solvers.sandboxes.EnvelopeAmortizationModel.solve(
calls,
setup,
work_per_call,
overhead_cap,
)Compare fresh and retained envelope setup costs.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| calls | int | Positive number of calls. | required |
| setup | Quantity | Nonnegative setup time quantity. | required |
| work_per_call | Quantity | Positive useful time per call. | required |
| overhead_cap | float | Allowed setup share, dimensionless and between zero and one. | required |
Returns
| Name | Type | Description |
|---|---|---|
| EnvelopeAmortizationResult | Useful work, setup and total durations, reuse speedup, setup share, and useful-work duration required by the overhead cap. |
Notes
Equation: T_fresh=N(S+W); T_retained=S+NW; W_min=S(1-phi)/phi.
Assumptions: Equal useful work and serial setup across calls.
Excludes: Idle retention cost, eviction, and overlapping work.
References
Derivation: retaining an envelope removes all but one setup charge. Solving setup / (setup + work) <= overhead_cap for work gives the minimum useful-work duration; this is a cost-accounting identity.
Examples
>>> from mlsysim.core.units import Q_
>>> r = EnvelopeAmortizationModel().solve(2, Q_(1,"s"), Q_(2,"s"), 0.2)
>>> r.per_call_total > r.per_trajectory_total
TrueSandboxPoolReserveModel
engine.solvers.sandboxes.SandboxPoolReserveModel()A warm sandbox pool under steady Poisson arrivals.
Active leases follow Little’s law, N = lambda T_hold. With s standby instances and a constant restore lead time T_init, a request misses when at least s earlier replacements are outstanding: P(Poisson(lambda T_init) >= s). Resident guest memory is a private image per lease, or one shared image plus dirty pages per lease and private state per standby under copy-on-write.
Methods
| Name | Description |
|---|---|
| solve | Size a warm pool against a Poisson miss target. |
solve
engine.solvers.sandboxes.SandboxPoolReserveModel.solve(
arrival_rate,
hold,
restore,
guest_memory,
dirty,
standby,
target_miss,
initial_reserve,
slow_factor,
)Size a warm pool against a Poisson miss target.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| arrival_rate | Quantity | Positive arrival rate, inverse time. | required |
| hold | Quantity | Positive lease holding time. | required |
| restore | Quantity | Positive restore lead time. | required |
| guest_memory | Quantity | Positive private guest memory, byte quantity. | required |
| dirty | Quantity | Nonnegative dirty memory per active guest, byte quantity. | required |
| standby | Quantity | Nonnegative private state per standby, byte quantity. | required |
| target_miss | float | Target miss probability, between zero and one. | required |
| initial_reserve | int | Nonnegative initial standby count. | required |
| slow_factor | float | Positive multiplicative restore-time slowdown. | required |
Returns
| Name | Type | Description |
|---|---|---|
| SandboxPoolReserveResult | Mean active leases, standby counts, Poisson miss probabilities, private and shared-pool memory in GB, and restore-time ceiling in ms. |
Notes
Equation: N=lambda T_hold; mu=lambda T_restore; miss=P(Poisson(mu)>=reserve).
Assumptions: Steady Poisson arrivals and constant restore lead time.
Excludes: Burst correlation, restore contention, and a guaranteed tail bound for non-Poisson arrivals.
References
Derivation: Little’s occupancy identity multiplies arrivals per second by lease duration. During a fixed restore interval, Poisson arrivals have mean arrival_rate * restore; calc_poisson_reserve chooses the smallest standby count meeting its upper-tail target. Pool memory adds one shared image, dirty pages for active leases, and private standby state.
Examples
>>> from mlsysim.core.units import Q_
>>> r = SandboxPoolReserveModel().solve(Q_(1,"1/s"), Q_(10,"s"), Q_(1,"s"), Q_(1,"GB"), Q_(0.1,"GB"), Q_(0.1,"GB"), 0.01, 1, 2)
>>> r.reserve_miss <= 0.01
TrueSyscallTaxModel
engine.solvers.sandboxes.SyscallTaxModel()The added time of calls ordinary system calls under each envelope.
A shared-kernel container pays a trap and an in-kernel filter per call, a microVM a native trap in its guest (device exits counted separately), and a user-space kernel a trap, emulation, and a switch to the emulator.
Methods
| Name | Description |
|---|---|
| solve | Compute serialized system-call overhead. |
solve
engine.solvers.sandboxes.SyscallTaxModel.solve(
calls,
trap,
filter,
emulate,
switch,
)Compute serialized system-call overhead.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| calls | int | Number of calls, nonnegative. | required |
| trap | Quantity | Native trap duration, positive time quantity. | required |
| filter | Quantity | Filter duration per call, nonnegative time quantity. | required |
| emulate | Quantity | Emulation duration per call, nonnegative time quantity. | required |
| switch | Quantity | Context-switch duration per call, nonnegative time quantity. | required |
Returns
| Name | Type | Description |
|---|---|---|
| SyscallTaxResult | Per-call durations, total serialized seconds, and the dimensionless userspace-to-microVM time ratio. |
Notes
Equation: T_container=N(trap+filter); T_guest=N trap; T_user=N(trap+emulate+switch).
Assumptions: Each call pays the same stated cost, with no overlap.
Excludes: Device exits, scheduling contention, and measured hypervisor behavior.
References
Derivation: add the trap and envelope-specific costs paid by one call, then multiply that duration by the call count. The guest baseline pays only the native trap, so dividing user-space duration by trap gives its relative tax.
Examples
>>> from mlsysim.core.units import Q_
>>> r = SyscallTaxModel().solve(2, Q_(1,"us"), Q_(1,"us"), Q_(2,"us"), Q_(1,"us"))
>>> r.container_total > r.microvm_total
TrueWorkspaceProvisioningModel
engine.solvers.sandboxes.WorkspaceProvisioningModel()Bytes to provision workspaces by full copy or copy-on-write, and the first-write payload under file or block granularity.
Payload only: drive times are lower bounds at the sequential rate, and metadata, journaling, and caching add traffic.
Methods
| Name | Description |
|---|---|
| solve | Compare full-copy and copy-on-write payloads. |
solve
engine.solvers.sandboxes.WorkspaceProvisioningModel.solve(
workspaces,
base_image,
written,
bandwidth,
fixture,
block,
modified,
)Compare full-copy and copy-on-write payloads.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| workspaces | int | Positive workspace count. | required |
| base_image | Quantity | Base image size, positive byte quantity. | required |
| written | Quantity | Bytes written per workspace, positive byte quantity. | required |
| bandwidth | Quantity | Positive sequential storage bandwidth, bytes per second. | required |
| fixture | Quantity | File copied on first write, positive byte quantity. | required |
| block | Quantity | Block copied on first write, positive byte quantity. | required |
| modified | Quantity | Logical modification size, nonnegative byte quantity. | required |
Returns
| Name | Type | Description |
|---|---|---|
| WorkspaceProvisioningResult | Full-copy and copy-on-write byte payloads, sequential-transfer times in seconds, and file-to-block amplification ratios. |
Notes
Equation: B_full=N B_image; B_cow=N B_written; T=B/bandwidth.
Assumptions: Each workspace writes the supplied payload at a constant bandwidth.
Excludes: Metadata, journaling, cache effects, and device contention.
References
Derivation: each workspace contributes either the whole image or its written payload. Dividing aggregate bytes by sequential bytes per second gives a transfer-time lower bound. First-write amplification divides file-size payload by block-size payload for the same logical change.
Examples
>>> from mlsysim.core.units import Q_
>>> r = WorkspaceProvisioningModel().solve(2, Q_(10,"GB"), Q_(1,"GB"), Q_(1,"GB/s"), Q_(1,"MB"), Q_(4,"KiB"), Q_(1,"KiB"))
>>> r.full_copy_time > r.cow_time
True