﻿# Runtime and resource limits

[中文](../../zh-CN/protection/resource-limits.md) · [Configuration](configuration.md#resource-fields) · [Protection guide](index.md)

Choose a FinSAFE limit that the operating system, executable version and execution mode enforce. Resource limits apply to protected local execution. Agent integrations separately determine which processes enter that boundary.

A runtime, memory or process limit does not cap model tokens, external API calls or third-party charges.

## Platform support and evidence

The Windows results use an installed **0.11.84** standalone CLI. The public **v0.11.85** macOS and Linux archives reuse executable **0.11.48**. Keep the archive tag and executable version separate. These results apply to the named entries and settings.

| Platform and tested entry | Runtime / timeout | Memory | Process count | CPU quota |
| --- | --- | --- | --- | --- |
| Windows 11 x64, 0.11.84 `run` / `self-confine` | `1500` ms stopped a five-second wait; exit 124 | `128M` installed a 134,217,728-byte Job limit; a bounded allocation failed | `2` allowed the main process and one child; another child was refused | **Not enforced in the tested `run`**: `1000 100000` was accepted, but Job CPU-control flags were zero |
| macOS 26.6.1 arm64, 0.11.48 personal CLI `run` | `1500` ms stopped `sleep 5` | **Not enforced in this entry**: 80 MiB allocation succeeded under `32M` | **Not enforced in this entry**: three extra processes started under `2` | Demo health reported **unenforced**; CPU quota was not measured |
| Linux, 0.11.48 personal CLI `run`, privileged Docker Desktop linuxkit / emulated amd64 | Stopped `sleep 5` | `32M` allocation test returned inner exit 137 | `2` prevented bubblewrap from forking; the application did not start | `10000 100000` reduced work in a bounded busy loop |

Windows **0.11.85 plugin-executable** trials stopped before workload launch: `transparent caller is not this installation's Inspector executable`. They establish no resource-enforcement result. The 0.11.84 tests do not establish 0.11.85 acceptance. Windows RestrictedToken, other desktop/plugin launches, macOS `self-confine` resource behavior and Linux `self-confine` quotas were not accepted by these tests.

The [Windows record](../reference/windows-verification-2026-12-03.md#resource-limits) contains the new controls and Job queries. The macOS/Linux rows attribute the earlier [macOS report](https://github.com/finogeeks/finsafe/issues/110#issuecomment-7372339261) and [Linux report](https://github.com/finogeeks/finsafe/issues/110#issuecomment-7373101907). The [Linux record](../reference/linux-verification-2026-12-03.md) distinguishes the public x64 archive from a separate aarch64 **0.9.105** binary; its Landlock results are not resource acceptance for public 0.11.48.

## Fields, units and scope

Windows Candidate paths are `policy.resources.<field>`. Personal macOS/Linux wrapper YAML uses top-level `resources.<field>`. Do not exchange complete configurations between them.

| Field | Input / unit | Scope and reaching the limit |
| --- | --- | --- |
| `timeout_ms` | Finite milliseconds, or `max` | Wall-clock execution limit. The recorded `run` task was stopped; Windows `self-confine` also timed out. It is separate from CPU time and model-request timeouts |
| `memory_max` | Memory size; Windows `128M` resolved to 134,217,728 bytes. Linux used `32M`. `max` sets no finite maximum in this field | Tested Windows: committed memory across the Job, rather than one process's working set. Linux: memory charged to the controlled cgroup. These accounting boundaries differ |
| `pids_max` | Count, or `max` | Windows: simultaneously active Job processes, including the launched program. Linux cgroup `pids.max` counts tasks/threads. Launcher overhead also needs room |
| `cpu_max` | Linux quota and period in microseconds; `10000 100000` is 10% of one CPU's time across the cgroup | Throttles CPU during a period. `100000 100000` is one CPU-equivalent, rather than all host CPUs. These tests establish no effective Windows/macOS quota |

The Job memory and process-count meanings follow Microsoft's [extended](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_extended_limit_information) and [basic Job limits](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_limit_information). Linux memory, task counting and CPU-period meanings follow the [cgroup v2 controllers](https://docs.kernel.org/admin-guide/cgroup-v2.html). Those sources describe OS mechanisms; the platform table states the product results.

### Defaults and unlimited values

The reviewed DSH/OpenCode Windows Candidate snapshots and tested standalone Candidate explicitly use `max` for timeout, memory and process count, with `cpu_max: '100000 100000'`. These are configuration baselines, not global defaults for every FinSAFE edition. `max` sets no finite limit in that field; host limits and other controls still apply. The CPU string does not prove Windows enforcement.

The macOS/Linux measurements used explicit wrapper settings. This guide does not assign defaults to omitted fields or borrow historical SaaS defaults. Set the required values explicitly. Do not substitute `0` for `max`: the tests did not establish a portable zero/unlimited convention. Tight process or memory limits can prevent the launcher/runtime from starting before application work begins.

## Configure and activate

| Platform / entry | Editing route | Host and activation conditions |
| --- | --- | --- |
| Windows Candidate / Effective | Change `policy.resources` in a copy of the selected Candidate; materialize with that installation's CLI; launch with the resulting `--yaml-path` | Prepared AppContainer configuration and required Inspector must match the installation. The tests required `prepare check` JSON `result: same`; no new permission application was performed |
| macOS personal CLI | Change top-level `resources` in the wrapper selected by `finsafe --policy <file> run` | Matching executable and system Seatbelt / `sandbox-exec` entry. A new launch loads settings. For tested 0.11.48 `run`, use timeout; the other resource fields did not enforce limits |
| Linux personal CLI | Change top-level `resources` in the selected wrapper, then start a new `run` | Matching helper/supervisor/shim, functional cgroup v2 and delegation of required controllers, plus the execution entry's bubblewrap/kernel prerequisites |

Follow [configuration activation](configuration.md#choose-the-activation-workflow) for installation-specific steps. A plugin without a slider may have another supported configuration interface; that does not make another installation's files interchangeable. This guide establishes no resource editors in desktop/plugin UIs. A successful YAML parse is not proof of controller readiness.

## Bounded Windows check: installed 0.11.84

This recipe was exercised on Windows 11 Pro 23H2 x64, build 22631, with Windows PowerShell 5.1 and an already prepared standalone configuration. It requires no Agent, model account or network request. It is not a 0.11.85 plugin recipe.

Save work. Select the EXE and Candidate from the **same installation**. These paths name the tested standalone layout. Create a disposable copy and preserve all other Candidate settings, including narrower file/network rules:

```powershell
$finshieldExe = 'C:\Program Files\FinSAFE\finsafe.exe'
$sourceCandidate = 'C:\ProgramData\FinSAFE\config\candidate.yaml'
$shellExe = Join-Path $env:WINDIR 'System32\WindowsPowerShell\v1.0\powershell.exe'
$trial = Join-Path $env:TEMP ('finsafe-resource-' + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $trial | Out-Null
$candidate = Join-Path $trial 'candidate.yaml'
$effective = Join-Path $trial 'effective.yaml'
Copy-Item -LiteralPath $sourceCandidate -Destination $candidate
& $finshieldExe --version
```

Edit **only** `policy.resources` in the copy. For the timeout check:

```yaml
# Inside the existing policy section; retain all other settings.
resources:
  timeout_ms: 1500
  memory_max: max
  pids_max: max
  cpu_max: '100000 100000'
```

Materialize a new output and check it. Stop on errors or any result other than `same`; do not apply new permissions to force a pass:

```powershell
& $finshieldExe config materialize --candidate $candidate --output $effective --json
if ($LASTEXITCODE -ne 0) { throw 'Materialization failed' }
$checkText = & $finshieldExe prepare check --yaml-path $effective --json
if ($LASTEXITCODE -ne 0) { throw 'Preparation check failed' }
$check = $checkText | ConvertFrom-Json
if ($check.result -ne 'same') { throw 'The test configuration is not prepared' }
$command = "[Console]::WriteLine('RESOURCE104-START'); [Threading.Thread]::Sleep(5000); [Console]::WriteLine('RESOURCE104-END')"
& $finshieldExe run --yaml-path $effective --stdio capture --json -- $shellExe -NoLogo -NoProfile -NonInteractive -Command $command
```

Recorded result: exit **124**, `timed_out: true`, `termination_reason: timeout_killed`; START appeared and END did not. A control with `timeout_ms: 10000` completed the same five-second wait. Total wrapper wall time includes startup. In installed 0.11.84, `run --help` returned `unknown flag: --help`; use `finsafe help` for its command listing.

### Other bounded checks

For each check, create a fresh Candidate/output pair, materialize and require `result: same`. Set `timeout_ms: 10000`, change **one** resource field and retain the other baseline values. Run each `$command` with the explicit `run` invocation above.

| Check | Opt-in setting and bounded workload | Recorded control / limited result |
| --- | --- | --- |
| Memory | `memory_max: '128M'`; hold at most ten 16 MiB arrays, touching their pages, and catch allocation failure | With `max`, held 160 MiB, exit 0. With `128M`, held 64 MiB, then `allocation_failed=MethodInvocationException`, exit 23. Runtime overhead also consumes Job memory |
| Process count | `pids_max: '2'`, memory `max`; attempt at most three five-second child processes and reap them in `finally` | With `max`, started/reaped three children. With `2`, one child started and the next start reported `Not enough quota is available to process this command` |

The bounded fixtures are [windows-memory.ps1](https://github.com/finogeeks/finsafe/blob/main/examples/resource-limits/windows-memory.ps1) and [windows-processes.ps1](https://github.com/finogeeks/finsafe/blob/main/examples/resource-limits/windows-processes.ps1). Save the selected file locally, set its corresponding resource value, and use a fresh checked Effective. Read the fixture on the host and pass its text inline; the protected `-File` route had a separate authorization failure in the recorded environment:

```powershell
$command = Get-Content -Raw -LiteralPath 'C:\YourFixtureDirectory\windows-memory.ps1'
& $finshieldExe run --yaml-path $effective --stdio capture --json -- $shellExe -NoLogo -NoProfile -NonInteractive -Command $command
```

For the process check, select `windows-processes.ps1` instead. Each script terminates its own bounded workload; no process-name-wide termination is used.

The [Windows evidence record](../reference/windows-verification-2026-12-03.md#resource-limits) specifies the probes and independent Job queries. Both results were also observed through Windows `self-confine`. An allocation failure need not kill a process that catches it. A caught process-spawn error can leave exit 0; inspect the actual error and child counts.

No Windows CPU-quota recipe is offered: under `cpu_max: '1000 100000'`, `QueryInformationJobObject` returned CPU-control flags/rate **0/0**, and a 2.5-second loop showed no corresponding reduction. The printed `windows_job_limits` CPU string was not an applied cap. See Microsoft's [CPU rate-control flags](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information).

### Recorded macOS and Linux settings

The macOS report used `resources.timeout_ms: 1500` with `/bin/sleep 5`. Linux reported `memory_max: '32M'`, `pids_max: '2'` and `cpu_max: '10000 100000'` in separate bounded tests. These are recorded settings, not complete policies or newly executed cross-platform recipes. Use the wrapper and launch syntax supported by the recorded release. This Windows-hosted work verifies no new executable macOS/Linux example.

## Stopping and cleanup

Use [Sessions, stopping and cleanup](lifecycle.md) for normal exit, interruption, parallel work and retained authorization. This section keeps the resource-test outcomes beside their limit settings.

Windows `run` with a 1500 ms timeout stopped a five-second parent/child test; the captured child PID was no longer running after return. Job queries showed kill-on-close. This covers that Job and launch, not independent services or every desktop/plugin lifecycle.

macOS/Linux records confirm timeout stopped the named `run`; they do not establish that every descendant was reaped. Separate interruption tests left a child alive after macOS SIGTERM. Public Linux 0.11.48 with `network: host` left a child alive; `network: none` reaped it. Timeout, interruption and application exit are distinct events.

Keep results, errors and effective settings; independently check remaining test children. After children exit, remove only the exact disposable directory you created and verified. Installed Candidate/Effective files were not replaced by these tests. Stopping execution does not undo files, revoke credentials or cancel remote requests already accepted.

## Services and spending budgets

| Requirement | Status in the reviewed local entries |
| --- | --- |
| SaaS tenant concurrency | Separate service capability; local `pids_max` is not a tenant limit. No service-specific setter/default verified here |
| Host scheduling / fleet budgets | Separate administrator/scheduler contract; not a per-`run` resource field |
| Model tokens | No supported token-budget setter established by this review. A short process can still submit a large request |
| External API-call count | No call-count budget established. Destination permission does not count requests |
| Monetary budget | No monetary-budget control established. Remote services determine billing; resource limits are not a charge ceiling |

This describes the public interfaces/evidence reviewed, not every enterprise delivery. Confirm service requirements through the [enterprise delivery scope](../enterprise/index.md). Document separately verified service controls separately from local execution defaults.
