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