pub struct Sandbox { /* private fields */ }Expand description
Clonable because two places run under the same policy without being able to share one
value: the agent’s tool registry and the interface’s !command.
Implementations§
Source§impl Sandbox
impl Sandbox
pub fn new( cfg: &ToolsConfig, workspace: &Path, scripts_dir: Option<&Path>, ) -> Self
Sourcepub fn off() -> Self
pub fn off() -> Self
A sandbox that does nothing. Tests of the process-group kill (and anything else that wants the plain child) use this, so the two mechanisms stay separately testable.
pub fn mode(&self) -> ShellIsolate
Sourcepub fn refuses(&self) -> bool
pub fn refuses(&self) -> bool
Whether a mode that promised containment will refuse instead of running at all. True only
for fs without bubblewrap; process degrades instead.
Sourcepub fn refusal(&self) -> Option<ToolError>
pub fn refusal(&self) -> Option<ToolError>
The refusal a mode owes when it cannot be honoured, as the error the tool returns, or
None when a command may run. One place, because three tools now ask it: shell,
script and execute_code all start a process and all answer to the same policy (#550).
Sourcepub fn degraded(&self) -> bool
pub fn degraded(&self) -> bool
Whether isolation was asked for and could not be given: the run happens anyway, and the
result says so. Only process degrades; fs refuses in Sandbox::plan, because a
read-only promise is not one to keep halfway.
Sourcepub fn status(&self) -> String
pub fn status(&self) -> String
What config check and the docs print: the mode, and whether the mechanism is there.
Sourcepub fn plan(
&self,
program: &OsStr,
args: &[OsString],
cwd: &Path,
) -> Result<Plan, ToolError>
pub fn plan( &self, program: &OsStr, args: &[OsString], cwd: &Path, ) -> Result<Plan, ToolError>
The program and arguments to run instead of program itself.
cwd is passed to bubblewrap rather than left to the caller so the directory is resolved
inside the namespace, which is the only place it is guaranteed to mean the same thing.
Sourcepub fn plan_with(
&self,
program: &OsStr,
args: &[OsString],
cwd: &Path,
extra_rw: &[PathBuf],
) -> Result<Plan, ToolError>
pub fn plan_with( &self, program: &OsStr, args: &[OsString], cwd: &Path, extra_rw: &[PathBuf], ) -> Result<Plan, ToolError>
Sandbox::plan with extra directories bound read-write at their own path under fs.
The tool bridge is why this exists: its socket is created after the sandbox is built, so a
contained child can only reach it if the run binds the socket’s directory (#550). Under
process the whole filesystem is already there, and under off nothing is wrapped.
Sourcepub fn is_suggested_hide(&self, path: &Path) -> bool
pub fn is_suggested_hide(&self, path: &Path) -> bool
Whether path is one of the hides the build suggests rather than one a person wrote.
Sourcepub fn skipped_hides(&self) -> Vec<(&PathBuf, HideSkip)>
pub fn skipped_hides(&self) -> Vec<(&PathBuf, HideSkip)>
The hides a profile asked for that will not be applied, and why — for config check and
the docs to name, rather than leave someone believing a path is hidden when it is not.