aboutsummaryrefslogtreecommitdiffstats
path: root/tools/docker_exec.sh
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2026-01-31 14:08:20 +0100
committerLeonard Kugis <leonard@kug.is>2026-01-31 14:08:20 +0100
commit94000f6b6d07b31151deccc4e3e1fdccf5b5c487 (patch)
treec0d5450d5d445fc675d899d72de2957d5e6e289b /tools/docker_exec.sh
parent4742f1125021f6bc1a2631c6e54cf6365f9d37f6 (diff)
downloadllm-functions-docker-94000f6b6d07b31151deccc4e3e1fdccf5b5c487.tar.gz
Added docker scripts
Diffstat (limited to 'tools/docker_exec.sh')
-rw-r--r--tools/docker_exec.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/docker_exec.sh b/tools/docker_exec.sh
new file mode 100644
index 0000000..66f79bc
--- /dev/null
+++ b/tools/docker_exec.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# @describe Execute a shell command inside a sandbox container.
+# @option --container! Container name/id to execute in.
+# @option --command! Shell command to run (executed via sh -lc inside container).
+# @option --timeout_sec Timeout in seconds. Default: 60
+
+main() {
+ local c="${argc_container}"
+ local cmd="${argc_command}"
+ local t="${argc_timeout_sec:-60}"
+
+ if ! docker ps --format '{{.Names}}' | grep -qx "$c"; then
+ echo "ERROR: container not running: $c" >> "$LLM_OUTPUT"
+ exit 2
+ fi
+
+ local out
+ local rc=0
+ out="$(timeout "${t}" docker exec "$c" sh -lc "$cmd" 2>&1)" || rc=$?
+
+ printf '{"exit_code":%d,"output":%s}\n' "$rc" "$(python -c 'import json,sys; print(json.dumps(sys.stdin.read()))' <<<"$out")" >> "$LLM_OUTPUT"
+}
+
+eval "$(argc --argc-eval "$0" "$@")"
+