Skip to content

Containerization safe mode - #30

Merged
daniel-larraz merged 22 commits into
kind2-mc:mainfrom
Jabe03:containerization-safe-mode
Oct 1, 2026
Merged

daniel-larraz merged 22 commits into
kind2-mc:mainfrom
Jabe03:containerization-safe-mode

Conversation

@Jabe03

@Jabe03 Jabe03 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Adds Docker-backed safe mode execution to the Kind 2 Java API.

When safe mode is enabled, Kind 2 executions are launched inside a Docker container with configurable CPU, memory, and swap limits. The configured Kind 2 executable and solver binaries are mounted into the container and exposed through fixed container paths.

Interpreter execution has also been updated to support safe mode. Generated interpreter input files, and Lustre files when using the URI-based interpreter API, are mounted read-only into the container before Kind 2 is started.

Changes

  • Added Docker-based execution when safeMode is enabled.
  • Added configurable safe mode CPU, physical memory, and combined memory/swap limits.
  • Added validation for safe mode CPU and memory limit settings.
  • Added configurable Docker image support.
  • Mounts the configured Kind 2 executable into the container at a fixed path.
  • Uses fixed container paths for configured SMT solver binaries while retaining host paths outside safe mode.
  • Added Docker-compatible execution for both interpreter APIs.
  • Mounts temporary interpreter input files and Lustre files read-only when required.
  • Added a minimal Dockerfile for the safe mode runtime environment.

@daniel-larraz daniel-larraz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found 7 problems in this PR. The first (safeMode null check) breaks every existing caller, even with safe mode off; the rest affect safe mode.

Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated

@daniel-larraz daniel-larraz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review of 920aae8.

Fixed: safeMode null checks, z3Bin null handling, per-instance CPU/memory/swap limits, and the absolute-path check for KIND2 (now applied to the interpreter path too). Thanks!

Partly fixed: solver mounts (target names don't match the fixed paths in getOptions; smtinterpol can't work) and swap/memory consistency (the swap setter isn't checked, and units are 1000-based).

Not fixed: commas in mounted paths. The new space escaping also breaks paths that contain spaces, which worked before.

New: setApiDebug() in callKind2 writes a debug file on every run.

Details are in the inline comments.

Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated

@daniel-larraz daniel-larraz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review of 58e981a.

Everything from the last round is addressed: mount paths are now CSV-quoted (commas and spaces both work), solvers and Kind 2 are mounted at the fixed paths getOptions uses, smtinterpol's paths match and the image now includes Java, the swap setter is checked against the memory limit, units are 1024-based, and the leftover setApiDebug() call is gone. Thanks!

One remaining bug in memoryValueToBytes (uppercase units) and a stale comment. Details are in the inline comments.

Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
Comment thread src/main/java/edu/uiowa/cs/clc/kind2/api/Kind2Api.java Outdated
@daniel-larraz
daniel-larraz merged commit 574a732 into kind2-mc:main Oct 1, 2026
1 check passed
daniel-larraz added a commit to kind2-mc/kind2-language-server that referenced this pull request Oct 2, 2026
Adds configurable CPU, memory, and swap limits for Kind 2 executions
running in safe mode.

The language server now reads the following environment variables:

- `KIND2_SAFE_MODE_CPU`
- `KIND2_SAFE_MODE_MEMORY`
- `KIND2_SAFE_MODE_SWAP`

When safe mode is enabled, these values are applied to each `Kind2Api`
instance before executing Kind 2. The gateway also forwards these
settings to the language server and provides defaults of `2.0` CPUs,
`2g` of physical memory, and `2g` of combined memory and swap.

The README has been updated with documentation and examples for
configuring these limits on Linux/macOS, PowerShell, and Command Prompt.

## Changes

- Added safe mode CPU, memory, and swap environment variables to the
gateway.
- Added parsing and propagation of those values in the language server.
- Applied configured resource limits through the Kind 2 Java API.
- Added logging of the active safe mode resource limits.
- Documented the new configuration options and defaults in the README.

This PR is dependent on [LSP PR
30](kind2-mc/kind2-java-api#30), as the API
needs to handle the usage limit method calls.

---------

Co-authored-by: Daniel Larraz <daniel-larraz@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants