Repository navigation
Python Interop (Future)
Status: future / post-v1.
Current v1 policy: python_ffi.* is not part of the supported language surface and is rejected at
check/compile time.
Curlee is verification-first and capability-based. Python interoperability must not introduce ambient authority (file/network/system access) or non-determinism unless the user explicitly opts in.
- Keep Python interop explicitly unsafe.
- Keep Python interop capability-gated.
- Preserve Curlee’s determinism and “no ambient authority” by default.
- Enable a future “Curlee shield” workflow where Curlee verifies preconditions before delegating work.
- Full Python embedding or rich data marshaling.
- Making Python calls available without an explicit opt-in.
- Allowing Python interop to bypass verification.
Python interop is a trust boundary: Python can do anything, and Curlee cannot generally verify or sandbox arbitrary Python.
Design rules:
- Any call that may trigger Python execution must be within an explicit
unsafecontext. - Any
python_ffi.*API is only callable from anunsafecontext.
Python execution is treated as an effect requiring an explicit capability token.
- Capability name:
python.ffi - Default: not granted
Without python.ffi, the runtime must refuse to execute any Python interop call.
Granting python.ffi is a large escape hatch: it enables effects that Curlee cannot generally
verify or reason about.
Curlee therefore supports an optional OS sandbox wrapper for the Python runner on Linux.
- Capability name:
python.sandbox - Default: not granted
When python.sandbox is granted, the VM should invoke the Python runner via an OS sandbox wrapper
(initially: bubblewrap / bwrap) rather than executing the runner directly.
Rules:
- Sandboxing is opt-in (explicit capability).
- If sandboxing is requested but the wrapper cannot be executed, Curlee must fail deterministically (no silent fallback to an unsandboxed execution path).
Python interop lives behind a dedicated module boundary so it is easy to audit.
- Module name:
python_ffi - All APIs in this module are unsafe + effectful.
- Imported usage should be clearly visible in source (no implicit magic).
Keep the initial surface minimal to avoid committing to a rich FFI ABI too early.
Planned MVP shape:
-
python_ffi.call(module, function, args...) -> String- arguments are marshaled as strings or integers initially
- return values are strings or integers
Errors must be surfaced as Curlee diagnostics or runtime errors with span information where possible.
The intended safe workflow:
- Curlee function declares precise contracts (
requires/ensures) over inputs. - Curlee verifies these contracts.
- Only after verification succeeds, an
unsafeblock calls Python. - Curlee validates/parses the Python result back into Curlee types.
Guideline: treat Python results as untrusted and validate invariants at the boundary.
Decision: use a subprocess runner, not in-process CPython embedding.
Rationale:
- Isolation: a separate process contains crashes/memory corruption.
- Operational simplicity: no
libpythonABI/version coupling. - Capability story: the runner is invoked only when
python.ffiis granted.
Tradeoffs:
- Without OS sandboxing, granting
python.ffieffectively opts into ambient authority and nondeterminism. - Curlee should not pretend Python execution is deterministic.
Decision (current): granting python.ffi is an explicit opt-in to nondeterminism.
If Curlee later adopts a separate nondeterminism gate, this page must be updated.
- Add a dedicated helper process (e.g.
curlee_python_runner) invoked by the VM opcode. - Define a tiny request/response protocol over stdin/stdout (JSON Lines) for
module,function, and a minimalargsencoding.
- Launch controls (best-effort isolation):
- set
PYTHONHASHSEED=0 - run Python in isolated mode (
-I) and (optionally) no-site (-S) if compatible - clear environment variables except an explicit allowlist
- enforce a wall-time limit + output size limit
- set
- Decide whether nondeterminism needs its own explicit CLI gate (separate from
python.ffi) or whetherpython.ffiis sufficient.
- Implement the runner and wire it to the VM opcode.
- Decide whether we split
python.ffiinto refined capabilities (e.g.,python.ffi+fs:read,net:client, etc.). - Harden the Linux sandbox profile and decide whether to support an alternate backend (e.g. nsjail).
- Expand marshaling once structured-data MVP exists.
- Public language-level Python interop is intentionally de-scoped from v1.
- Any future re-introduction must be issue-gated with explicit acceptance criteria for safety, determinism boundaries, diagnostics, and tests.