Skip to content

Add IsolationSpec and LocalInterpreter subprocess mode - #1

Open
MaximeRivest wants to merge 1 commit into
cmpnd-ai:mainfrom
MaximeRivest:isolation-subprocess-mode
Open

Add IsolationSpec and LocalInterpreter subprocess mode#1
MaximeRivest wants to merge 1 commit into
cmpnd-ai:mainfrom
MaximeRivest:isolation-subprocess-mode

Conversation

@MaximeRivest

@MaximeRivest MaximeRivest commented Aug 17, 2026

Copy link
Copy Markdown

this PR is to share example code on how local, native language interpreters (not wasm) could be isolated using native operating system tooling.

see the first 70 lines of: docs/isolation.md to get an idea of the purpose / value of this.

to get a sense of what it takes to accomplish this, see:

  • src/dspy_interpreters/isolation/_plain.py
  • src/dspy_interpreters/isolation/_darwin.py
  • src/dspy_interpreters/isolation/_windows.py

this is just meant to inform and 'stash' the general approach for properly implemented version if you see the value.

Add a guarantee-based isolation vocabulary (dspy_interpreters.isolation) and a
LocalInterpreter(mode="subprocess", isolation=IsolationSpec(...)) mode that
runs generated code in a separate local worker process behind OS confinement.

- IsolationSpec names portable guarantees (filesystem_allowlist,
  no_ambient_network, memory_capped, cpu_time_capped, process_count_capped,
  wall_time_capped, clean_environment, private_tmp, killed_with_host,
  no_new_privileges, reduced_kernel_surface). A backend that cannot provide a
  requested guarantee refuses with IsolationUnsupportedError; it never
  downgrades silently. probe() reports what the machine can enforce and
  isolation_report shows the mechanism behind each guarantee after start.
- Worker script (stdlib + ctypes) speaks the Modal-style JSON-lines protocol
  on private fds and applies the policy ratchet before serving: rlimits,
  PR_SET_PDEATHSIG, Landlock, unshare(CLONE_NEWUSER|CLONE_NEWNET),
  PR_SET_NO_NEW_PRIVS, seccomp-bpf denylist (x86_64, aarch64).
- Linux backend: bwrap or native (Landlock + namespaces + seccomp) launcher,
  cgroup v2 caps through systemd-run --user --scope with rlimit fallbacks.
- macOS backend: sandbox-exec Seatbelt profile (experimental), RLIMIT_CPU,
  RLIMIT_NPROC, ppid watchdog; memory caps refused.
- Windows backend: Job Object memory/CPU/process caps and kill-on-close;
  filesystem allowlist and no-network refused (AppContainer not implemented).
- Plain backend on any OS for an unconfined worker process.
- Tests: worker protocol and ratchet, plain and confined conformance suites,
  Linux live tests for both launchers, plan/profile/struct tests for macOS
  and Windows, spec validation. Only Linux was exercised live.
- Docs: docs/isolation.md, README security table and usage,
  abstraction-boundaries note, run_conformance subprocess entry.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TxvuSh9guNNcZKpWrQe4RA
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.

1 participant