Repository navigation
Python Interop (Future)
Status: planned. Any Python interoperability must remain explicitly unsafe and capability-gated.
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.
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; it should be explicitly opted into.
- 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.). - Add OS-level sandboxing on Linux behind explicit capabilities.
- Expand marshaling once structured-data MVP exists.
- A stub exists in the interop layer and refuses to run without
python:ffi. - Tests should cover missing capability behavior.