Expand description
Sandbox command construction for isolated tool execution.
Builds the argv needed to run a shell command inside a container or a fresh
set of Linux namespaces (unshare(1)), plus container-engine detection. This
module is pure argv assembly + PATH probing - it never spawns a process
itself. The caller (the daemon’s SandboxManager) owns the actual
tokio::process::Command spawn and container lifecycle, so everything here is
deterministic and unit-testable without any runtime installed.
The container engine is just a binary name ("docker", "podman",
"nerdctl", "finch", …): Leviath isn’t prescriptive about which one you
run, only that it speaks the common run/exec/rm verbs. Auto-detection
(detect_container_engine) prefers Docker then Podman, but a blueprint can
name any binary.
Keeping the sole namespace-vs-container / Linux-vs-not knowledge here (behind
namespace_supported and a cfg!) means callers stay platform-agnostic,
consistent with the rest of this crate.
Structs§
- Container
RunSpec - Parameters for creating a long-lived, exec-able container.
Constants§
- KNOWN_
ENGINES - The container engines auto-detection probes for, in preference order. A blueprint may name any other Docker-CLI-compatible binary explicitly.
Functions§
- binary_
on_ path - Whether
binresolves to a regular file on anyPATHentry. - container_
exec_ argv - argv to run one shell command inside a running container.
- container_
rm_ argv - argv to force-remove a container (best-effort teardown).
- container_
run_ argv - argv to start a detached, auto-removed container that idles (
sleep infinity) so shell calls canexecinto it repeatedly (warm container). - detect_
container_ engine - Detect an available container engine on
PATH, returning its binary name. Prefers Docker, then Podman (seeKNOWN_ENGINES). - detect_
container_ engine_ with - Testable core of
detect_container_engine:existsreports whether a binary name is available. First match inKNOWN_ENGINESwins. - mount_
allowed - Whether
pathis safe to bind-mount into an agent container. - namespace_
argv - argv to run one shell command under fresh Linux namespaces via
unshare(1). - namespace_
supported - Whether Linux-namespace sandboxing (
unshare) is possible on this host. Only Linux ships the namespaces +unshare(1)this relies on.