Tool for executing bash commands.
Routes through the active Condukt.Sandbox. With Sandbox.Local this
spawns a real bash subprocess on the host; with Sandbox.Virtual it runs
inside the in-memory bashkit interpreter with no host process spawning; with
Sandbox.Microsandbox it executes inside the guest microVM; with
Sandbox.Kubernetes, inside the session's pod.
Output that is too long keeps its first and last lines, up to 2000 lines or 50KB in all, since a command's start says what it ran and its end how it finished.
Parameters
command- The bash command to executecwd- Directory to run the command in (optional, relative to the sandbox's cwd)timeout- Timeout in seconds (optional, default: 120)
Long-running commands
In a session, on a sandbox that implements Condukt.Sandbox.start_process/4,
as Local, Kubernetes, and Microsandbox do, a command runs as a sandbox
process named by process_id/2 from the session id and the tool call id,
apart from the call that started it:
- Its output streams as it arrives, as
{:tool_output, tool_call_id, chunk}events to stream subscribers and the notifier, and into the tool'soutputin the session's view. SeeCondukt.Tool.output/2. - A command still running after
:park_aftermilliseconds (default10_000) parks the call until it exits, asCondukt.Parkdescribes, so the call holds no process and the session's tool timeout does not cut off a long build. Only the command's owntimeoutdoes. - Aborting the turn kills the command, in the foreground or parked.
Draining the session for another node (
Condukt.Sessions.stop/2withdrain: true) leaves it running. - A sandbox that implements
Condukt.Sandbox.watch_process/3is asked to report the exit itself when the call parks, so the call wakes even when the node that ran its watcher restarted. - A call that runs again with the same session and tool call ids, such as
one a restarted session retries, finds the command by its id and
follows it instead of starting it twice. On
Kubernetesthe command runs in the pod, so it survives the BEAM node restarting.
Options, as {Condukt.Tools.Bash, park_after: 30_000}:
:park_after- milliseconds a command runs in the foreground before the call parks:replay_safe-truedeclares calls replay-safe (see the Sessions and Persistence guide), so a resumed run reruns an interrupted call, which then follows the command it started. Set it only on a sandbox whose processes outlive the session's node. Defaults tofalse.
Elsewhere, such as on Virtual, or when the tool runs outside a session,
the call runs the command with Condukt.Sandbox.exec/3 and returns when it
ends.
Summary
Functions
Callback implementation for Condukt.Tool.description/0.
Callback implementation for Condukt.Tool.name/0.
Callback implementation for Condukt.Tool.parameters/0.
The id of the sandbox process that runs a call's command.
Callback implementation for Condukt.Tool.replay_safe?/0.
Functions
Callback implementation for Condukt.Tool.description/0.
Callback implementation for Condukt.Tool.name/0.
Callback implementation for Condukt.Tool.parameters/0.
The id of the sandbox process that runs a call's command.
A host that needs the process after the session is gone, such as to stop
it, finds it with Condukt.Sandbox.read_process/4 and
Condukt.Sandbox.stop_process/2 under this id.
Callback implementation for Condukt.Tool.replay_safe?/0.