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