Skip to main content

capsule_runtime/
lib.rs

1// `security::harden_process_dumpable` needs one `unsafe { libc::prctl(...) }` call on Linux;
2// `#[allow(unsafe_code)]` on that item overrides this crate-level default of `deny` rather
3// than `forbid`, since `forbid` cannot be overridden by a narrower `allow` anywhere in the crate.
4#![deny(unsafe_code)]
5
6pub(crate) mod a2a;
7#[cfg(test)]
8mod a2a_conformance;
9#[cfg(test)]
10mod a2a_conformance_tests;
11pub(crate) mod agent;
12#[cfg(feature = "alloc-bench")]
13pub mod alloc_bench;
14pub mod artifact;
15pub mod artifact_config;
16pub(crate) mod artifact_removal;
17pub mod artifact_supply;
18pub mod background_command;
19pub mod bindings;
20pub(crate) mod cancel;
21pub(crate) mod capsule_facts;
22pub(crate) mod cgroup;
23pub mod child_launch;
24pub(crate) mod compiled_forms;
25pub mod containment;
26pub(crate) mod control_plane;
27pub(crate) mod conversation;
28pub(crate) mod conversation_import;
29pub mod delegation;
30pub mod delegation_plane;
31pub mod detached;
32pub(crate) mod detached_reconcile;
33pub mod door_auth;
34pub(crate) mod driver_choice;
35// Public so the `runtime_out!` / `runtime_err!` macros resolve `$crate::diagnostic` from outside
36// this crate, and so `mur run`'s launch path writes its lines the same way the runtime does.
37pub(crate) mod credential_gateway;
38pub mod diagnostic;
39pub(crate) mod dns_resolver;
40pub(crate) mod done_check;
41pub(crate) mod egress_proxy;
42pub mod errors;
43pub(crate) mod fence;
44pub mod formation;
45pub mod formation_credentials;
46pub mod formation_launch;
47pub(crate) mod gateway_credential;
48pub mod guest_roots;
49pub(crate) mod harness_session;
50pub(crate) mod hooks;
51mod host_facts;
52pub mod host_paths;
53pub mod host_warnings;
54pub(crate) mod http_client;
55pub(crate) mod identity;
56pub(crate) mod images;
57pub(crate) mod inference_import;
58pub(crate) mod inference_retry;
59pub(crate) mod install_grant;
60pub(crate) mod instruction_files;
61pub(crate) mod interpreter_runtime;
62pub(crate) mod keep_working;
63pub mod lanes;
64pub mod lifeline;
65pub mod limits;
66pub mod mac_token;
67pub mod manifest_files;
68pub(crate) mod member_call;
69pub mod model_limits;
70pub mod murmur_home;
71pub(crate) mod murmur_md;
72pub mod namespace_probe;
73pub mod network_namespace;
74pub(crate) mod network_policy;
75pub mod origin;
76pub(crate) mod otel;
77pub(crate) mod outgoing;
78pub mod peer_handoff;
79pub(crate) mod peer_tasks;
80#[cfg(test)]
81mod pinned_port;
82pub mod plan;
83pub mod precompile;
84pub mod proc_view;
85pub mod process_driver;
86pub(crate) mod protected_paths;
87pub mod provider_tool;
88pub(crate) mod reachability;
89pub(crate) mod recipes;
90pub mod records_dir;
91pub mod registration;
92pub(crate) mod required_fields;
93pub mod resource_plane;
94pub mod resources;
95pub mod retention;
96pub mod roster;
97pub mod running;
98pub mod runtime;
99pub mod runtime_dir;
100pub(crate) mod sandbox;
101pub mod sealed;
102pub mod security;
103pub mod session_check;
104pub(crate) mod session_process;
105pub mod session_status;
106pub(crate) mod shell;
107#[cfg(test)]
108mod source_scan;
109pub mod spawn_credential;
110pub mod spawn_envelope;
111pub(crate) mod spend;
112pub mod staged_runtime;
113pub mod state_store;
114pub(crate) mod stream_events;
115pub(crate) mod streaming;
116pub(crate) mod task_io_import;
117pub mod temp_dir;
118pub(crate) mod tokens_import;
119pub(crate) mod tool_annotations;
120pub(crate) mod tool_call_progress;
121pub mod tool_names;
122pub(crate) mod trace;
123pub(crate) mod trace_blobs;
124pub(crate) mod trust_store;
125pub mod types;
126pub(crate) mod wit_versions;
127pub mod workdir_fs;
128pub mod workdir_snapshot;
129pub mod workdir_writes;
130
131pub use artifact_config::{
132    configured_artifact_names, lower_artifact_config, ARTIFACT_CONFIG_ENV,
133    MAX_ARTIFACT_CONFIG_BYTES,
134};
135pub use artifact_supply::{SourceSupply, SourcedArtifact};
136pub use containment::{
137    applied_mechanism, attach_extra_roots, check_containment_floor, containment_shortfall_reason,
138    detect_containment_decision, detect_sealed_shortfall, detect_userns_grant, doctor_runtime_dir,
139    explain_scope, install_from_places, read_only_advisory_for, render_install, render_read_only,
140    render_records_dir, render_routes, render_runtime_dir, render_temp_dir, route_table,
141    uncovered_route_warning, warn_on_uncovered_routes, ContainmentDecision, DoctorDirReports,
142    ExportsFilesReport, ExtraRootReport, FilesystemBoundaryReport, FilesystemRestriction,
143    ImagesReport, PreopenReport, PreopenSurface, Route, RouteInputs, RouteReport, RuntimeDirReach,
144    RuntimeDirReport, ScopeReport, ShortfallCause, StateStoreReport, TempDirReport,
145    UnconfinedReport, HOST_PROCESS_MECHANISM, UNCONFINED_APPLIES_TO,
146};
147pub use diagnostic::{diagnostic_workdir, set_diagnostic_workdir, Emitted};
148pub use manifest_files::{
149    manifest_file_reports, InstalledCapsule, ManifestFileReport, ManifestFiles,
150};
151// `mur run --explain-scope` derives an allowlisted interpreter's runtime directories through the
152// same function `stage_session` does, so the report and the session's grants name one set.
153// `mur install` keeps host facts through the same derivation, so the first launch keeps them.
154pub use interpreter_runtime::{
155    capsule_writable_roots, derive_interpreter_runtimes, keep_host_facts,
156    DerivedInterpreterRuntime, HostFactsKept, InterpreterRuntimes,
157};
158// Both pass the same host facts cache, and `session_start.host_facts` reports what a launch kept.
159pub use host_facts::{HostFactsCache, HostFactsReason, HostFactsSource, HostFactsUse};
160pub use murmur_home::{usable_murmur_home, HomeUnusable, HOME_UNUSABLE_HINT};
161pub use namespace_probe::{MountAttempt, MountAttemptError, MountStep, NamespaceReading};
162pub use network_namespace::{
163    check_egress_namespace, detect_egress_namespace_failure, skip_without_egress_namespace,
164    CreationStep, EgressNamespaceBlocker, EgressNamespaceFailure, NamespaceAttemptError,
165};
166pub use records_dir::{
167    records_dir_root, records_group, records_group_under, RecordsDir, HOME_SUBDIR, HOOKS_SUBDIR,
168    RECORDS_DIR_ENV, RECORDS_DIR_NAME, RESULTS_SUBDIR, RESULT_FILE,
169};
170pub use runtime_dir::{
171    runtime_dir_inside_warning, runtime_dir_placement, RuntimeDirPlacement, RUNTIME_DIR_ENV,
172    RUNTIME_DIR_GUEST_PATH,
173};
174pub use session_check::{
175    copy_tree_into, walk_tree, CheckOutcome, CheckResult, CheckRunner, SessionCheck, TreeEntry,
176};
177// `mur run --explain-scope` derives the host trust store through the same function
178// `stage_session` does, so the report and the session's grants name one set.
179pub use trust_store::{derive_trust_store, TrustStorePath};
180// `network_policy` is a private module; `preopen_reports` is re-exported because `mur run
181// --explain-scope` and `mur doctor` both resolve the preopen set the same way `stage_session`
182// does, and one resolver shared by all three is what keeps the report a description of the launch.
183pub use network_policy::preopen_reports;
184// `sandbox` is a private module; `HostProbe` is re-exported because the freshness of a session's
185// host reading is asserted from integration tests outside this crate. `find_on_path` is re-exported
186// so a caller outside this crate resolves a binary name the way the shell allowlist and the
187// invoked-binary report already resolve one, rather than open-coding the `PATH` walk again.
188pub use sandbox::{detect_landlock_abi, find_on_path, landlock_doctor_lines, HostProbe};
189pub use sealed::{
190    classify_installed_profile, classify_profile_attachment, inspect_installed_profile,
191    inspect_profile_attachment, InstalledProfileState, ProfileAttachment, SealedBlocker,
192    SealedShortfall, UsernsGrant, SEALED_APPARMOR_ATTACHMENT_PATHS, SEALED_APPARMOR_PROFILE_PATH,
193    SEALED_APPARMOR_PROFILE_SHA256,
194};
195pub use streaming::STREAM_EXTENSION_URI;
196// `cgroup` is a private module, but the entry points below are consumed from `murmur-cli` — the
197// three test-support probes from its integration tests, the cgroup scope and `io.max` reporting
198// from `mur run --explain-scope` and `mur doctor`, and the swap-bound reporting from `mur doctor`,
199// each of which has to answer the question a launch does without staging a session. Re-exported
200// here rather than duplicating a probe once per crate that needs it.
201pub use cgroup::{
202    active_swap_areas, cgroup_delegation_available, explain_scope_probe, io_max_device_available,
203    probe_scope, probe_swap_control, render_cgroup_scope, requires_process_bounding,
204    skip_without_host_support, CgroupScopeReport, CgroupScopeStatus, IoMaxReport, IoMaxStatus,
205    ScopeProbe, SwapControl, SCOPE_SWAP_MAX,
206};
207// The door's protocol version and error tables: every client of a door sends the header pair,
208// and names the error it is answered with through `A2aError::from_code`.
209pub use a2a::{
210    murmur_state_name, A2aError, MurmurError, A2A_EXTENSIONS_HEADER, A2A_PROTOCOL_VERSION,
211    A2A_VERSION_HEADER,
212};
213pub use child_launch::{
214    child_workdir_for, format_workdir_identity, launch_child_capsule, parse_workdir_identity,
215    ChildLaunchRequest, LaunchedChild, ParentWorkdirSource, MUR_BINARY_ENV,
216    PARENT_WORKDIR_SNAPSHOT_FLAG, READINESS_TOKENS_FLAG, WORKDIR_IDENTITY_FLAG,
217};
218// The delegation types and constants stay module-qualified beyond these: `Spawner` and
219// `SpawnerHandle` are what a caller of `launch_child_capsule` composes, and the rest of the
220// module — the outcome, the file, the two headers — is read by name from `delegation::`.
221pub use delegation::{CompletionAddress, Spawner, SpawnerHandle};
222// The delegating side's own types. `DelegationPlane` is built by `launch_session` and reached
223// only through the `delegate-task` dispatch branch, so what leaves this crate is the vocabulary a
224// reader of a trace or a tool result needs, plus the bound and its override.
225pub use delegation_plane::{
226    DelegationLaunch, DelegationOrigin, DelegationPlane, DelegationRequest, DelegationResult,
227    StartedDelegation, DELEGATION_RESULT_TIMEOUT, DELEGATION_TIMEOUT_ENV,
228};
229// `reachability` is a private module, but both of its entry points are consumed from
230// `murmur-cli`'s `mur doctor` as well as from `stage_session`, so they are re-exported here — the
231// same facade shape `check_staged_runtime_floor` has, without making the module's internals
232// (`shebang_interpreter_name`, the probe, the prefix helpers) part of any crate's API.
233pub use door_auth::{
234    bearer_header, door_posture, is_loopback_bind, public_door_bind_warning, public_door_warning,
235    render_public_door_warning, AuthRefusal, DoorAuth, DoorExposure, DoorGrant, DoorToken,
236    PublicDoorDisclosure, DOOR_TOKEN_ENV,
237};
238pub use errors::{RuntimeError, UnreachableEntrypoint};
239pub use formation::{FormationId, FormationPeer, FormationPeers};
240pub use formation_credentials::{
241    FormationAuthority, FormationBundle, FormationMember, FormationToken, FormationVerifier,
242    FormationVerifyKey, FORMATION_CALL_SCOPES, FORMATION_CHANNEL_ENV,
243};
244pub use host_warnings::{
245    host_warnings_reported, host_warnings_reported_in, HOST_WARNINGS_REPORTED_ENV,
246};
247pub use lanes::TaskLane;
248#[cfg(unix)]
249pub use lifeline::{ChildLifeline, FormationLifeline, MemberLifeline, SpawnerLifeline};
250pub use lifeline::{FORMATION_LIFELINE_ENV, SPAWNER_LIFELINE_ENV};
251pub use limits::ExecutionLimits;
252pub use murmur_artifact::{
253    AfterTask, DoneCheck, KeepWorking, LifecycleConfig, LifecycleOverride, TaskAcceptance,
254};
255// The types and header names are flat; `origin::from_wire` and `origin::stamp_for_peer` stay
256// module-qualified, because their bare names say nothing about tasks.
257pub use origin::{TaskOrigin, TaskProvenance, TrustClass, PEER_ORIGIN_HEADER, PEER_TRUST_HEADER};
258pub use peer_handoff::{
259    audience_from_card, handle_id, handle_peer_request, is_peer_path, mint, stored_path_for,
260    verify, HandleError, HandlePayload, MintedHandle, PeerError, PeerMintKey, PeerPlane,
261    AUDIENCE_HEADER, HANDLE_ID_HEADER, PEER_INBOX_DIR, PEER_PATH_PREFIX,
262};
263pub use reachability::{
264    check_interpreted_entrypoints_reachable, warn_on_unreachable_toolchain_helpers,
265    ToolchainHelperReport, ToolchainHelperWarning, UnprobedToolchainDriver,
266};
267pub use registration::{check_roost_health, deregister_session, register_session, SessionOutcome};
268pub use resource_plane::{
269    check_export_root, check_peer_files_root, handle_resource_request, reason_phrase,
270    symlink_policy, DeclaredExport, ListEntry, ListResponse, ReadResponse, ResourceError,
271    ResourcePlane, ResourceResponse, SymlinkPolicy, RESOURCE_PATH_PREFIX,
272};
273pub use resources::HostResourceLimits;
274// `retention` is its own public module rather than a set of flat re-exports: `mur conversation`
275// consumes six of its entry points and four of its types, and a facade that wide is a second
276// place for the names to drift.
277pub use retention::{
278    find_context_dirs, list_records, locate_message, prune_records, prune_sessions,
279    read_context_dir, remove_record, truncate_record, ContextContents, ContextDir,
280    HarnessSessionEntry, MessageLocation, MessageStatus, PrunedRecord, PrunedSession, RecordHeader,
281    RecordSummary, RemovedRecord, TruncationMarker, TruncationOutcome,
282};
283pub use roster::{
284    admit_roster, admit_roster_file, caller_overflow_fix, caller_overflow_warning, AdmittedMember,
285    AdmittedRoster, CallerOverflow, RosterEdge, RosterRefusal,
286};
287// The running-capsule vocabulary a reader of a record needs. The verbs stay module-qualified —
288// `running::list`, `running::verify`, `running::prune`, `running::running_dir` — on the same terms
289// as `origin::from_wire`: their bare names say nothing about capsules.
290pub use running::{Liveness, ProcessState, RunningGuard, RunningRecord, SignalOutcome};
291pub use runtime::{
292    check_env_allow_reaches_guests, check_no_reserved_tool_names, has_subprocess_route_at_staging,
293    launch_session, launch_session_handling_sigterm, secret_shaped_env_grants, stage_session,
294    stripped_env_allow_entries, undeclarable_runtime_pin_role,
295    warn_on_gateway_endpoint_in_network_allow, warn_on_interpreter_runtime_grants,
296    warn_on_launch_only_gateway_credential, warn_on_secret_shaped_env_grants,
297    warn_on_unmetered_gateways, warn_on_userns_restriction_disabled_host_wide,
298    warn_on_workdir_exec, SecretShapedEnvGrant, StrippedEnvAllowEntry,
299};
300// The one question about a variable name a caller outside the runtime needs answered: would the
301// credential backstop drop it, and by which pattern. `shell` is otherwise crate-private, and these
302// are what `secret_shaped_env_grants` and `check_env_allow_reaches_guests` judge a
303// `capabilities.env.allow` entry with.
304pub use shell::{
305    credential_backstop_drops, credential_backstop_match, BackstopMatch, BackstopPatternSource,
306};
307pub use spawn_credential::{
308    SpawnApproval, SpawnCredential, SPAWN_APPROVAL_HEADER, SPAWN_CREDENTIAL_HEADER,
309};
310pub use spawn_envelope::{EnvelopeAxis, EnvelopeViolation, SpawnEnvelope};
311pub use staged_runtime::check_staged_runtime_floor;
312pub use state_store::{
313    ensure_state_store, state_store_reports, validate_store_name, STATE_PREOPEN_NAME,
314};
315pub use trace::{PlanTraceAppender, ResourceTraceAppender};
316pub use types::{
317    capability_policy_from_runtime_manifest, ArtifactRequest, CapabilityPolicy,
318    InstalledArtifactSummary, LaunchEnding, LaunchResult, LockExpectation, ResolvedLockArtifact,
319    ResumeMode, ResumeRequest, StageRequest, StagedSession,
320};
321// The one way the runtime touches a path inside a capsule's workdir, and what it reports when a
322// link there is refused.
323pub use workdir_fs::{
324    EntryKind, RefusalReason, WorkdirError, WorkdirOperation, WorkdirRefusal, WorkdirRoot,
325};
326// The declaration `--explain-scope` prints and `trace.jsonl` carries as
327// `session_start.effective_grants.runtime_writes`. Flat, on the same terms as the other report
328// types: a consumer of a scope report reads these names off it.
329pub use runtime_dir::SESSION_ID_PLACEHOLDER;
330// What a delegated child started with when its parent copied its work folder into the child's:
331// the parent's `delegation_start.workdir_snapshot` and the child's
332// `session_start.effective_grants.parent_workdir`.
333pub use workdir_snapshot::{
334    copy_workdir, ParentWorkdirReport, SkipReason, SkippedEntry, SnapshotError, SnapshotLimits,
335    WorkdirSnapshot,
336};
337pub use workdir_writes::{
338    render_runtime_writes, RuntimeWriteCondition, RuntimeWriteKind, RuntimeWriteReport,
339};
340// The served version of each `murmur:*` package, and the WIT levels: the committed, numbered sets
341// of those versions, the newest of which is the one this host serves.
342pub use wit_versions::{served_wit_level, wit_levels, SERVED_WIT_PACKAGES, WIT_LEVELS_FILE};