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