[BUG] Fix k8s_execute_command kubectl exec argv handling and honor container
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
Start in pkg/k8s/k8s.go at handleExecCommand and trace how the command, container, and command errors reach the kubectl invocation and tool result. Add or update tests for whitespace-separated commands, container selection, and failures that expose stdout/stderr; done means the listed kubectl argv and error behavior are covered without weakening the stated validation.
Written by the indexing model from the issue text.
Description
Summary
The Kubernetes k8s_execute_command tool appears broken for typical multi-token commands: the logical command line is forwarded to kubectl exec incorrectly, the optional container parameter is ignored, and failures often surface only as generic exit status 1, which hides stdout/stderr and leads agents astray.
Current behavior
- Commands with operators like
|are rejected upfront by validation (potentially dangerous characters detected) — that part may be intentional for a strict safe mode, but it blocks common diagnostics (e.g.ss -tnp | grep 5000). - Even simple whitespace-separated commands (e.g.
echo test,ls -la,which ss,ss -tnp) fail withexit status 1despite working when invoked manually viakubectl exec … -- …. - In
pkg/k8s/k8s.go, the exec path passescommandtokubectlin a way that effectively treats the entire string as a single argument after--, instead of splitting into argv tokens (-- echo testvs-- "echo test"). - The
containerfield from the tool request does not result inkubectl exec -c <container>, so targeting a specific container in a multi-container pod is unreliable.
Expected behavior
- Commands without shell metacharacters should run with
kubectl-compatible argv: after--, each token becomes a separate argument (standardkubectl exec … -- cmd arg1 arg2 …). - When
containeris set and valid,kubectl execmust receive-c <container>. - On failure, surface
stderr/stdout(and non-zero exit) in the tool result/error path instead of opaqueexit status 1wherever possible.
Versions / scope
Still reproducible in the latest release v0.2.0 and on main (verified 2026-05-16): in pkg/k8s/k8s.go, handleExecCommand still passes the full command string as a single argv element after kubectl exec … -- and does not map the tool parameter container to kubectl exec -c …. The same behavior was already present in v0.1.3 and v0.1.4 — this code path did not change between those tags and v0.2.0 / current main.
A quick search of this repository’s issues/PRs did not find a dedicated report for k8s_execute_command / handleExecCommand (e.g. by name k8s_execute_command); if this duplicates something, please link and close.
Related but distinct: #54 / #55 (Cilium-focused kubectl exec -n). This report is about the general k8s_execute_command contract (argv splitting, -c, and error propagation).
Suggested upstream fix direction
- Structured API preferred long-term:
command+args[], or robust parsing rules documented and tested (avoid ambiguity with quoted args if staying string-only). - Honor
container→ always add-cwhen non-empty after validation. - Keep strict validation by default where appropriate; if shell/pipe features are needed, expose an explicit, opt-in mode (approval / documented risk) rather than silent breakage.
- Tests:
echo test,ls -la,ss -tnp, multi-container pod with-c, plus error cases that assert stderr is visible.
- Dominant language
- Go
- Stars
- 35
- Forks
- 30
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 3
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from kagent-dev/tools
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
kagent-dev/tools#54 ·
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
kagent-dev/tools#82 ·
Maintainers usually reply within 3 days
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
kagent-dev/tools#80 ·
Maintainers usually reply within 3 days
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
kagent-dev/tools#69 · 1 comment ·
Maintainers usually reply within 3 days
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
kagent-dev/tools#68 · 1 comment ·
Maintainers usually reply within 3 days
All issues in kagent-dev/tools
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
521xueweihan/HelloGitHub#3789 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 12 days
-
stage-fail
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
siyuan-note/bazaar#2282 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openshift/kube-compare#307 ·
Maintainers usually reply within 1 day