Condukt.Tools.Bash (Condukt v3.0.0)

Copy Markdown View Source

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 execute
  • cwd - 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's output in the session's view. See Condukt.Tool.output/2.
  • A command still running after :park_after milliseconds (default 10_000) parks the call until it exits, as Condukt.Park describes, so the call holds no process and the session's tool timeout does not cut off a long build. Only the command's own timeout does.
  • Aborting the turn kills the command, in the foreground or parked. Draining the session for another node (Condukt.Sessions.stop/2 with drain: true) leaves it running.
  • A sandbox that implements Condukt.Sandbox.watch_process/3 is 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 Kubernetes the 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 - true declares 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 to false.

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

description()

Callback implementation for Condukt.Tool.description/0.

name()

Callback implementation for Condukt.Tool.name/0.

parameters()

Callback implementation for Condukt.Tool.parameters/0.

process_id(session_id, tool_call_id)

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.

replay_safe?()

Callback implementation for Condukt.Tool.replay_safe?/0.