---
id: agent-command-execute
title: "Execute command"
description: "Executes a command on a specific agent."
sidebar_label: "Execute command"
hide_title: true
hide_table_of_contents: true
api: eJztWG1vI7cR/ivEoMAlh9VaurNb334IoDgO6rbwGXe69grbsClypGWOS25Irm1V0H8vhkutVi+5FyRN06D+IK9WQ84zzzwzfFlC4HMPxTWM52gC3GYg0Qun6qCsgQLOn1A0AT3jTNiq4kYyaxhnvkahZkowTuNyyMDW6DiNupBQQHx9l4YU2M4CGXgUjVNhAcX1EqbIHbpxE0oorm9Xtxk8DUyjda15mFlXQbGENMWd4RVCAUdxYsi691wkpOkFrDJw+GODPnxr5YKmoK/KoYQiuAZpqAk0SbEEXtdaiQj76AdP8yzBixIrTk9hUZNPO/0BBfmsHQUZFPoeskOG2xx+F79N0bNQYkcjPcdg2KPSmiWK8j037dydDx+cMnPIAE1TUeJoIFDMM4e+HHjbOIF+P5OTvu9FjczONhjyG3NjvmE5u6fp7gt2IO9aGWSPKpTMxjm5ZmgelLOmoigeuFN8qmmIkYy7eUOvfX5jvklT70C8L9ib9k1iJiJ55ln6PWeTUvnOvbTombGBpXQyLqVKOCQPPL8xxMoTr2pNREVeVhnQb5/OUZ+dGCg9HAxvP0OikjTkUJI+4SRYNsV16iVRxZ4/v7QBnz8vGFnXPJRkFXZH+tI2WrLaKhPWBjOrJTr2WKLDnryUZ8r4wLWOLrZIovkHwQ5EJQczpfFIVLGCepF/HneHlTCzrg/9QICHx6XopsiUSaG5igd2/9fzfxbs7+O/vTu/3wllCZdXd+OzycXry7uz15eT8/cTKODZH5aXrycX31+cjfu/rGC1yqDTaC9E7hxfQAYqYOX3M7o6FHs3T8pnzb1HeShtO5ivCcIIIpIXcLuiP2qRGkWw7vOIX1t3XK/reZucrYSCtoJriN6CClEJcdhZi/VN2z+jENopIhXpuYiCZb3255uq4m4Rl4to0gXdSltZw1JPhgweuG7wcANNvWxdsl1hHdbpnky/TAFbAthLxXYefpK+jpPU3NbN6+O0BNvZtzW6HvVRdnZbfEfULlqhG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5mbexKYD7ZxxE7wt9B1hx6jWW2Oz6CFcLluLif2AZrWCLIUS6DusaDP7b8A9Fds=
sidebar_class_name: "post api-method"
info_path: docs/api/control-plane
custom_edit_url: null
---

import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";
import ParamsDetails from "@theme/ParamsDetails";
import RequestSchema from "@theme/RequestSchema";
import StatusCodes from "@theme/StatusCodes";
import OperationTabs from "@theme/OperationTabs";
import TabItem from "@theme/TabItem";
import Heading from "@theme/Heading";

<Heading
  as={"h1"}
  className={"openapi__heading"}
  children={"Execute command"}
>
</Heading>

<MethodEndpoint
  method={"post"}
  path={"/controlplane/agent_command"}
  context={"endpoint"}
>
  
</MethodEndpoint>



Executes a command on a specific agent.

<Heading
  id={"request"}
  as={"h2"}
  className={"openapi-tabs__heading"}
  children={"Request"}
>
</Heading>

<ParamsDetails
  parameters={undefined}
>
  
</ParamsDetails>

<RequestSchema
  title={"Body"}
  body={{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"command":{"type":"object","description":"Describes the command the agent will execute.","properties":{"type":{"type":"string","enum":["exec","refresh-sources"],"description":"The command type of the agent.\n\n> . `exec`: Executes a command line with optional environment variables and arguments.\n>\n> . `refresh-sources`: Refreshes the agent's sources. This command does not require additional data.\n","example":"exec"},"data":{"type":"object","description":"The command line and environment variables.","properties":{"cmdline":{"type":"string","description":"The command line to be executed.\n> **Note**: The path to the command line should point to the folder where the agent is installed.\n","example":"path-to-cmd-file/cmd"},"environment":{"type":"object","description":"The environment variables for the command.\n> **Note**: The environment variables should be in the format `KEY: VALUE`.\n","example":{"NP_ACTION_CONTEXT":"'${NOTIFICATION_CONTEXT}"}},"arguments":{"type":"array","items":{"type":"string"},"description":"The arguments to be passed to the command line.\n","example":["arg1","arg2"]}}}}},"selector":{"type":"object","description":"The selector for the agent.\n","example":{"environment":"local"}}},"title":"agentCommandRequest"},"examples":{"example: exec command":{"summary":"Example command execution request","value":{"command":{"type":"exec","data":{"cmdline":"path-to-cmd-file/cmd","environment":{"NP_ACTION_CONTEXT":"'${NOTIFICATION_CONTEXT}"},"arguments":["arg1","arg2"]}},"selector":{"environment":"local"}}},"example: refresh sources":{"summary":"Example command to refresh agent sources","value":{"command":{"type":"refresh-sources","data":{}},"selector":{"cluster":"aec13961-1ad1-4c88-a57a-935f8848c911"}}}}}}}}
>
  
</RequestSchema>

<StatusCodes
  id={undefined}
  label={undefined}
  responses={{"200":{"description":"Command executed successfully.","content":{"application/json":{"schema":{"type":"object","properties":{"selector":{"type":"object","description":"The selector for the agent.\n","example":{"environment":"local"}},"command":{"type":"object","description":"Describes the command the agent will execute.","properties":{"type":{"type":"string","enum":["exec"],"description":"The command type of the agent.\n","example":"exec"},"data":{"type":"object","description":"The command line and environment variables.","properties":{"cmdline":{"type":"string","description":"The command line to be executed.\n> **Note**: The path to the command line should point to the folder where the agent is installed.\n","example":"path-to-cmd-file/cmd"},"environment":{"type":"object","description":"The environment variables for the command.\n> **Note**: The environment variables should be in the format `key: value`.\n","example":{"NP_ACTION_CONTEXT":"'${NOTIFICATION_CONTEXT}'"}},"arguments":{"type":"array","items":{"type":"string"},"description":"The arguments to be passed to the command line.\n","example":["arg1","arg2"]}}}}}},"title":"agentCommandResponse"}}}},"4XX":{"description":"Client error responses due to invalid input or missing parameters.","content":{"application/json":{"schema":{"type":"object","required":["statusCode","error","message"],"properties":{"statusCode":{"type":"integer","description":"HTTP status code representing the specific client error (e.g., 400, 401, 403, 404).","example":400},"code":{"type":"string","description":"A machine-readable error code that categorizes the server failure.","example":"bad_request"},"error":{"type":"string","description":"A brief, human-readable description of the error type (e.g., \"Bad Request\", \"Unauthorized\").","example":"Bad Request"},"message":{"type":"string","description":"Additional details about the error.","example":"The request was malformed or contained invalid parameters."}}}}}},"5XX":{"description":"Server error responses indicating an issue on the API side.","content":{"application/json":{"schema":{"type":"object","required":["statusCode","error","message"],"properties":{"statusCode":{"type":"integer","description":"HTTP status code representing the specific server error (e.g., 500, 502, 503).","example":500},"code":{"type":"string","description":"A machine-readable error code that categorizes the server failure.","example":"internal_server_error"},"error":{"type":"string","description":"A brief, human-readable description of the error type (e.g., \"Internal Server Error\", \"Service Unavailable\").","example":"Internal Server Error"},"message":{"type":"string","description":"Additional details about the error.","example":"An unexpected error occurred. Please try again later."}}}}}}}}
>
  
</StatusCodes>


      