blob: 66f79bce716d9cb26a499d0ebcafc9b848cb34bb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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" "$@")"
|