hashicorp/nomad · error

command is not present

Error message

command is not present

What it means

The allocation exec endpoint requires an actual command to run. The command is assembled from the exec request's cmd/command plus args (and from job action definitions in the job action path). If the assembled req.Cmd slice is empty, there is nothing to execute, so the handler returns this 400 error before contacting the task driver.

Source

Thrown at client/alloc_endpoint.go:321

	// If an action is present, go find the command and args
	if req.Action != "" {
		task := alloc.LookupTask(req.Task)
		if task == nil {
			return new(int64(http.StatusBadRequest)),
				fmt.Errorf("task %s not found in allocation %s", req.Task, alloc.ID)
		}
		jobAction := task.GetAction(req.Action)
		if jobAction == nil {
			return new(int64(http.StatusBadRequest)),
				fmt.Errorf("action %s not found in task %s", req.Action, req.Task)
		}

		// append both Command and Args
		req.Cmd = append([]string{jobAction.Command}, jobAction.Args...)
	}

	if len(req.Cmd) == 0 {
		return new(int64(400)), errors.New("command is not present")
	}

	capabilities, err := ar.GetTaskDriverCapabilities(req.Task)
	if err != nil {
		code := new(int64(500))
		if nstructs.IsErrUnknownAllocation(err) {
			code = new(int64(404))
		}

		return code, err
	}

	// check node access
	if capabilities.FSIsolation == fsisolation.None {
		exec := aclObj.AllowNsOp(alloc.Namespace, acl.NamespaceCapabilityAllocNodeExec)
		if !exec {
			return nil, nstructs.ErrPermissionDenied
		}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Pass a non-empty cmd (first element is the binary) in the exec request
  2. If using a job action, define its Command (and optional Args) in the job spec
  3. Fix the caller/CLI wrapper to reject empty commands before calling the API
  4. Validate user input so blank/whitespace commands are rejected client-side

Example fix

// before
{"Task":"web","Cmd":[]}
// after
{"Task":"web","Cmd":["/bin/sh","-c","ls"]}
Defensive patterns

Strategy: validation

Validate before calling

if len(cmd) == 0 && len(args) == 0 {
  return errors.New("exec requires a command: provide cmd/args or a job action with a Command")
}

Type guard

func hasCommand(cmd []string) bool { return len(cmd) > 0 && strings.TrimSpace(cmd[0]) != "" }

Try / catch

err := client.Allocations().Exec(ctx, alloc, task, false, cmd, stdin, stdout, stderr, nil)
if err != nil && strings.Contains(err.Error(), "command is not present") {
  return fmt.Errorf("no command given: usage: nomad alloc exec <alloc> <task> <cmd...>")
}

Prevention

When it happens

Trigger: POSTing to the alloc exec API with no 'cmd' and no 'args' (or an exec job action that defines neither Command nor Args, leaving req.Cmd empty).

Common situations: Client SDKs serializing an empty command array; CLI tools like 'nomad alloc exec <alloc>' invoked without a command; job action specs missing the command field; templated scripts where the command variable expands to empty.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/a818401df07a0b75. Report an issue: GitHub.