derailed/k9s · error

shell exec failed: %w

Error message

shell exec failed: %w

What it means

This wraps a runK() failure for the banner'd shell command k9s builds (kubectl exec ... sh -c <shellCheck> with a green banner naming the pod/container). Every root cause of runK bubbles here: kubectl missing from PATH, kubectl resolving via cwd (ErrDot), or the TUI failing to suspend. The %w preserves that underlying error.

Source

Thrown at internal/view/exec.go:389

	if len(cfg.Command) > 0 {
		args = append(args, cfg.Command...)
		args = append(args, cfg.Args...)
	} else {
		if platform == windowsOS {
			args = append(args, "--", "cmd", "/c", winShellCheck)
		}
		args = append(args, "sh", "-c", shellCheck)
	}
	slog.Debug("Running command with args", slogs.Args, args)

	c := color.New(color.BgGreen).Add(color.FgBlack).Add(color.Bold)
	err = runK(a, &shellOpts{
		clear:  true,
		banner: c.Sprintf(bannerFmt, fqn, co),
		args:   args},
	)
	if err != nil {
		return fmt.Errorf("shell exec failed: %w", err)
	}

	return nil
}

func nukeK9sShell(a *App) error {
	ct, err := a.Config.K9s.ActiveContext()
	if err != nil {
		return err
	}
	if !ct.FeatureGates.NodeShell || a.Config.K9s.ShellPod == nil {
		return nil
	}

	ns := a.Config.K9s.ShellPod.Namespace
	ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
	defer cancel()

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

  1. Read the wrapped cause — 'not in your path' → install kubectl; 'must not be in the current working directory' → remove ./kubectl; 'unable to run command' → retry after UI settles
  2. Confirm kubectl version works from the exact directory/environment k9s runs in
  3. Restart k9s after fixing PATH so it re-inherits the environment
Defensive patterns

Strategy: try-catch

Try / catch

err := runK(a, opts)
if err != nil {
    switch {
    case strings.Contains(err.Error(), "not in your path"):
        // install kubectl
    case strings.Contains(err.Error(), "current working directory"):
        // remove ./kubectl
    case strings.Contains(err.Error(), "unable to run command"):
        // retry after TUI settles
    }
}

Prevention

When it happens

Trigger: Pressing the shell key on a pod/container when kubectl is not installed or only present as ./kubectl in k9s' working directory, or when the app cannot suspend the TUI to hand over the terminal.

Common situations: Shelling into pods from workstations without a proper kubectl install; per-project kubectl binaries; k9s launched from GUI launchers with a stripped PATH so kubectl is invisible to the process.

Related errors


AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15). Data as JSON: /api/errors/f6d08650f2ac9790. Report an issue: GitHub.