pub struct ShellCommand {
pub command: String,
pub timeout_secs: u64,
pub cwd: Option<String>,
}Expand description
A shell command with template substitution and timeout.
The command field is a template string with {var} placeholders.
At execution time, the placeholders are replaced with values from a
HashMap<String, String>. The command is run via sh -c (or cmd /C
on Windows) with the substituted variables also available as TH_*
environment variables.
This type backs the custom-tools system: each custom tool wraps a
ShellCommand template executed with the tool’s arguments substituted.
Fields§
§command: StringCommand template, e.g. "docker run --rm {image} sh -c \"$TH_COMMAND\"".
timeout_secs: u64Timeout in seconds. Default: 30.
cwd: Option<String>Working directory for the command. If None, inherits the current
directory of the TinyHarness process.
Implementations§
Source§impl ShellCommand
impl ShellCommand
Sourcepub fn render(&self, vars: &HashMap<String, String>) -> String
pub fn render(&self, vars: &HashMap<String, String>) -> String
Render the command template by substituting {var} placeholders.
The renderer is quote-context-aware: it tracks whether each
{var} placeholder appears inside single quotes, double quotes, or
unquoted in the template, and applies the appropriate escaping:
| Context | Strategy |
|---|---|
| Unquoted | Wrap in single quotes (shell_escape) |
Inside "..." | Escape ", \, $, ` for double-quote context |
Inside '...' | Close the quote, insert shell_escaped value, reopen |
This prevents broken quoting when the template already wraps a
placeholder in quotes, e.g. echo "{user_input}" or echo '{tool}'.
Missing variables (not present in vars) are left as-is — the
{placeholder} appears literally in the rendered command.
Sourcepub async fn execute(
&self,
vars: &HashMap<String, String>,
) -> Result<String, String>
pub async fn execute( &self, vars: &HashMap<String, String>, ) -> Result<String, String>
Execute the command asynchronously.
Returns Ok(stdout) on success (exit code 0), or Err(message) on
failure (non-zero exit, timeout, or spawn error).
The vars are used for both {var} template substitution and as
TH_* environment variables.
Sourcepub async fn execute_with_sandbox(
&self,
vars: &HashMap<String, String>,
sandbox: Option<&Sandbox>,
) -> Result<String, String>
pub async fn execute_with_sandbox( &self, vars: &HashMap<String, String>, sandbox: Option<&Sandbox>, ) -> Result<String, String>
ShellCommand::execute routed through an OS-level process sandbox.
Custom tools are arbitrary shell templates, so they get the same
containment as the run tool: with a sandbox configured, the command
runs inside it.