Skip to main content

aither_sandbox/
lib.rs

1//! Sandboxed shell execution with heel.
2//!
3//! This crate provides the general capabilities an embedder builds a
4//! terminal-style agent tool on:
5//!
6//! - [`Sandbox`] spawns a process under heel's sandbox, in a container or on
7//!   an SSH server, with live [`Grants`] and an [`EnvSource`] the embedder
8//!   fills at each launch.
9//! - [`Shell`] executes scripts for a model on a [`Sandbox`]: a carried
10//!   directory, jobs, waiting, output handling and [`ScriptPolicy`] checks
11//!   before a script runs.
12//! - [`ShellTool`] and the job control tools are ordinary
13//!   [`Tool`](aither_core::llm::Tool)s the embedder names and describes.
14//!
15//! The embedder owns the commands its scripts call back into, the programs
16//! its sandboxes run with and every sentence the model reads.
17//!
18//! ```rust,ignore
19//! use aither_sandbox::{Backend, Sandbox, Shell};
20//!
21//! let sandbox = Sandbox::new(Backend::Host { heel }, executor, working_dir);
22//! let shell = Shell::builder_on_host(sandbox, host_shell)
23//!     .interpreters(interpreters)
24//!     .limits(limits)
25//!     .output(output)
26//!     .wording(wording)
27//!     .tools(tools)
28//!     .build()
29//!     .await?;
30//! let tool = shell.tool();
31//! ```
32
33#![allow(clippy::module_name_repetitions)]
34
35mod bollard_exec;
36mod container;
37#[cfg(all(unix, feature = "jobserver"))]
38mod container_jobserver;
39mod events;
40mod foreground_wait;
41mod interpreter;
42mod job_registry;
43mod jobs;
44mod limits;
45mod memory;
46pub mod monitor;
47mod outage;
48mod output;
49mod output_compress;
50mod output_policy;
51mod output_treatment;
52mod policy;
53mod process_tree;
54mod shell_session;
55mod shell_syntax;
56mod spawn;
57mod ssh;
58mod stdin_watch;
59mod subagent;
60mod terminal;
61mod wording;
62
63/// The job control tools and the identities an embedder gives its shell tools.
64pub mod builtin;
65
66/// Jobserver token pool brokering across commands.
67#[cfg(all(unix, feature = "jobserver"))]
68pub mod jobserver;
69
70/// Declarative host-based network policy.
71pub mod network_policy;
72
73/// Isolated git for tests, shared with dependent crates through the `test-git` feature.
74#[cfg(any(test, feature = "test-git"))]
75pub mod test_git;
76
77/// A `heel` for tests, shared with dependent crates through the `test-heel`
78/// feature.
79#[cfg(any(test, feature = "test-heel"))]
80pub mod test_heel;
81
82/// Budgets for tests, shared through the `test-budgets` feature.
83#[cfg(any(test, feature = "test-budgets"))]
84pub mod test_budgets;
85
86/// The wording tests read, shared through the `test-budgets` feature.
87#[cfg(any(test, feature = "test-budgets"))]
88pub mod test_wording;
89
90/// Jobs placed in a container or on a remote host for tests, shared with
91/// dependent crates through the `test-util` feature.
92#[cfg(any(test, feature = "test-util"))]
93pub mod test_jobs;
94
95/// Id allocators for tests, shared with dependent crates through the
96/// `test-ids` feature.
97#[cfg(any(test, feature = "test-ids"))]
98pub mod test_ids;
99
100pub use bollard_exec::BollardContainerExec;
101pub use builtin::{
102    JobInputArgs, JobInputTool, JobKillArgs, JobKillTool, JobReadArgs, JobReadTool,
103    ShellToolSettings, ToolIdentity,
104};
105pub use container::{
106    ContainerImageSpec, ContainerLaunchSpec, ContainerPath, ContainerRuntimeKind, MountAccess,
107    MountRoot, MountRootError, MountSpec, RelativeContainerPath, RuntimePreference,
108};
109pub use events::{
110    DescendantsKilled, JobEnded, JobStarted, LongRunning, ShellEvent, ShellEvents, StdinBlocked,
111    StdinWatchFailed,
112};
113pub use foreground_wait::ForegroundWait;
114/// Re-export of heel's rolling network audit log for terminal-tool configuration.
115pub use heel::NetworkAuditLog;
116/// Re-export of heel's scheduling priority types for terminal-tool configuration.
117pub use heel::{CpuPriority, IoPriority, NiceLevel, ProcessPriority};
118pub use interpreter::Interpreter;
119pub use job_registry::{
120    Delivery, JobDelta, JobInfo, JobInputError, JobPlace, JobRead, JobStatus, KillCause,
121    OwedCompletion, PendingCompletion, UnchangedRead,
122};
123pub use jobs::{
124    AppendOutcome, Job, JobOutputAppender, JobWaitError, Jobs, RunOutcome, ScriptResult,
125};
126#[cfg(all(unix, feature = "jobserver"))]
127pub use jobserver::{
128    CommandFifo, JobBroker, JobBrokerService, JobPool, JobserverError, job_broker_channel,
129};
130pub use limits::{LiveDuration, ShellLimits};
131pub use memory::{
132    AnyContainerMemory, AnyFootprintReader, AnyFootprintRegistry, CgroupMemory, ContainerMemory,
133    ContainerSnapshot, FileFootprintRegistry, FootprintError, FootprintReader, FootprintRegistry,
134    JOB_MARKER_ENV, JobFootprint, JobMemory, MemoryDomain, MemorySize, MemorySnapshot,
135    ProbedContainerMemory, ResponseWindow, SystemFootprints,
136};
137pub use monitor::{
138    MonitorArgs, MonitorEnd, MonitorEnded, MonitorIncrement, MonitorRefusal, MonitorSettings,
139    MonitorSource, MonitorStalled, MonitorTool,
140};
141pub use network_policy::{
142    CompiledNetworkPolicy, NetworkPolicyConfig, NetworkPolicyError, NetworkPolicyMode,
143    NetworkVerdict,
144};
145pub use output::{MediaResolution, OutputFormat, OutputStore};
146pub use output_policy::{MediaBounds, OutputLimits, OutputPolicy};
147pub use output_treatment::{OutputTreatment, TreatOutput};
148pub use policy::{
149    AnyScriptPolicy, Carry, SandboxMode, ScriptCheck, ScriptDecision, ScriptDir, ScriptEnd,
150    ScriptOrigin, ScriptOutcome, ScriptPolicies, ScriptPolicy, ScriptRefusal,
151};
152pub use process_tree::{
153    JOB_MARKER_VAR, JobProcess, KillTreeError, ProcessTableError, kill_process_tree,
154};
155pub use shell_session::{
156    AnyContainerExec, ContainerExec, ContainerExecOutcome, ContainerProbe, ContainerProbeError,
157    ContainerShellRuntime, ExecLifetime, ShellSessionRegistry,
158};
159pub use shell_syntax::{
160    CommandId, LineId, PipelineId, PipelineStage, ShellCommand, ShellParseError, ShellScript,
161};
162pub use spawn::{
163    AnyDomainApprover, AnyIpcProvider, ApproveAllDomains, Backend, ChildExit, ContainerLaunch,
164    DenyAllDomains, Descendants, DomainApprover, DomainRequest, EnvSource, GitDirAccess,
165    GrantSnapshot, Grants, HostLaunch, HostRoute, HostRouteError, IpcProvider, LaunchInfo, Pipe,
166    RemoteLaunch, Sandbox, SandboxedChild, SpawnCommand, SpawnError, SpawnGrant, SpawnSpec, Stdio,
167    TreeLifetime,
168};
169pub use ssh::{
170    AnyPrepareSsh, PrepareSsh, PreparedSsh, SshPlatform, SshPrepareError, SshProbeError, SshServer,
171    SshServerError, probe_ssh_os,
172};
173pub use stdin_watch::StdinWatchSignal;
174pub use subagent::{
175    AnySubagentSpaces, CommitLedger, CommitLedgerError, CommitMark, ImportBudget, PreparedSpace,
176    RunSpace, SpacePreparationError, SubagentCommit, SubagentGrant, SubagentGrantError,
177    SubagentSpaces,
178};
179pub use terminal::{
180    CompletedCommand, DirectoryResetReason, Given, Missing, Script, Shell, ShellArgs, ShellBuilder,
181    ShellRunError, ShellTool, TerminalError, TimeoutKill, open_network_audit_log,
182};
183pub use wording::{
184    AnyShellWording, CallRefusal, CommandKilled, FoldedLines, JobInputSent, JobKillAsked,
185    JsonAsTsv, LineRange, MonitorStarted, OmittedLines, OutputSaved, Refused, RepeatedLines,
186    RunFailure, ShellWording, StoredBinaryPart,
187};