The CPython provider¶
Python blocks run in the CPython provider: a Rust program that embeds and
drives one CPython interpreter and implements the server side of
RuntimeProviderProtocolV1. It is the untrusted process of a cell. It runs
block code, third-party packages and native extensions, holds the live Python
objects they create, and reports what it observed. Authority stays with the
cell monitor and the nucleus. This page covers where the provider sits, how it
initialises CPython from sealed inputs, how its readiness is established, and
what crosses its boundary.
Inside the provider process¶
flowchart TB
MON["Cell monitor<br/>trusted"]
subgraph PROV["CPYTHON PROVIDER PROCESS, UNTRUSTED"]
direction TB
SRV["Protocol server<br/>Rust"]
subgraph PY["ONE CPYTHON INTERPRETER"]
direction TB
AD["Generated adapter<br/>and bindings"]
BLK["Reusable capability block,<br/>libraries, native extensions"]
LOOP["One asyncio runner"]
AD --> BLK
BLK --> LOOP
end
TAB[("Provider resource table<br/>live Python objects")]
SRV --> AD
SRV --> TAB
end
subgraph FS["READ-ONLY MOUNTS"]
direction LR
ART[("Provider artifact<br/>runtime layout")]
CAP[("Capsule and<br/>component roots")]
end
MON -->|"RuntimeProviderProtocolV1"| SRV
PY --> ART
PY --> CAP
The monitor reaches the provider through the provider protocol alone. The provider reports observed runtime facts and provider-local outcomes. Grants, kernel handles, scheduling, readiness, retry decisions and cell lifecycle transitions are produced by the monitor and the nucleus from those reports. See The provider protocol.
Sealed initialisation¶
Every provider artifact contains the provider executable, the exact CPython
runtime it was built against, its standard library and a measured
CpythonProviderRuntimeLayoutV1. See Provider binary. At
process start the provider:
- opens the layout from its verified read-only provider-artifact root;
- admits the layout identity and its relative paths;
- negotiates the provider protocol with the monitor;
- receives the closure-bound environment fingerprint and the ordered module roots;
- builds one initialisation plan from those sealed inputs;
- initialises CPython once;
- observes the resulting interpreter state before reporting preparation.
Initialisation is isolated. The provider supplies the executable, prefix and
home values and the complete module search path before CPython starts, and
turns off environment-based path discovery, argument parsing, the user site,
site import, signal-handler installation and bytecode writes. Safe-path mode
is on. sys.path is exactly the ordered module roots of the cell environment
view from start to finish, and initialisation is attempted once per process.
See Interpreter preparation.
Because every path is supplied from the sealed layout, PYTHONHOME,
PYTHONPATH, PYTHONUSERBASE, PYTHONSTARTUP, virtual-environment markers,
modules in the current directory and user-site hooks have no effect on the
interpreter a cell runs.
Readiness¶
Before it reports preparation, the provider compares the initialised interpreter with the plan:
- the CPython ABI;
- the executable and base executable;
- the prefix, base prefix, exec prefix and base exec prefix;
- the platform library directory and the filesystem encoding;
- the isolated, ignore-environment, no-site, no-user-site and safe-path flags;
- the exact ordered module search path.
A mismatch is a typed preparation fault, and the provider process stops.
A matching report is the provider's part. The monitor binds it to the digests of the runtime closure, the cell environment view, the native-loader view and the ordered module-root set. The nucleus admits readiness when that receipt also matches the authenticated monitor, the cell id, the cell epoch, the provider process and the issued preparation authority. See Process lifecycle.
Execution boundary¶
After initialisation the provider admits the compiled interface and imports the declared block module, the generated adapter and the generated bindings from a sealed capsule root. It then constructs declared class exports, dispatches by export and method ordinal, converts typed argument values into generated Python types, runs awaitables on its one runner, and converts results into typed provider outcomes.
| Stays inside the provider | Crosses to the monitor |
|---|---|
| Live Python objects, in the provider resource table | Typed values of the declared interface types |
| Provider-local resource ids | Resource and stream proposals for the monitor and nucleus to promote |
| Exception text and tracebacks | Declared errors and closed fault kinds |
See Module import and object construction, Call and resource invocation, Provider resource table and Exception adaptation and result classification.
The same server implements prepare, dispatch, interrupt, release,
health, quiesce and cooperative terminate. A runtime-fatal or
adapter-contract fault ends the provider session. Hard process termination is
performed by the monitor through the process cell.