All Products
Search
Document Center

Agent Run:Use the AgentRun CLI to manage AgentRun in terminals and CI pipelines

Last Updated:Aug 25, 2026

The AgentRun console is well suited for visually creating, debugging, and observing agents. When you need to perform the same operations from a terminal, a script, a CI pipeline, or another automated scenario, the AgentRun CLI provides a command-line entry point—from launching a Super Agent conversation with a single command to declaratively managing agent configurations in YAML and placing them under version control.

Note

Before you use the AgentRun CLI, familiarize yourself with the basic concepts described in AgentRun. For command parameters, default values, and exit codes, refer to the user manual in the AgentRun CLI repository.

Scenarios

Typical scenarios include:

  • Launch a Super Agent from a local terminal with a single command and start a conversation immediately.

  • Declaratively create or update a Super Agent in YAML and place the configuration under version control.

  • Deploy an Agent Runtime from a container image, or build the image in the cloud first and then deploy it.

  • Export an existing runtime to YAML that you can apply again, which simplifies copying, migration, and auditing.

  • Consume command output in JSON, YAML, or quiet format from scripts.

The CLI entry command is ar. You can also use the full command name agentrun. This topic uses ar by default. To create an agent visually in the console, see Create an agent with Quick Creation (no-code).

Install the CLI

We recommend that you install the precompiled binary directly, which does not require a local Python environment.

Linux or macOS:

curl -fsSL https://raw.githubusercontent.com/Serverless-Devs/agentrun-cli/main/scripts/install.sh | sh

Windows PowerShell:

irm https://raw.githubusercontent.com/Serverless-Devs/agentrun-cli/main/scripts/install.ps1 | iex

After the installation is complete, verify it:

ar --version
# or
agentrun --version

You can also install the CLI from PyPI:

pip install agentrun-cli

To pin a specific version, set AGENTRUN_VERSION before you run the installation script. To specify the installation directory, set AGENTRUN_INSTALL. Run the installation script again to upgrade to the latest version in place. To uninstall the CLI, delete the ar binary from the $AGENTRUN_INSTALL directory.

Configure credentials

All CLI commands rely on AccessKey credentials and a local profile. Complete the following one-time configuration before you use the CLI for the first time.

Grant permissions to the AccessKey pair

The RAM user or role that owns the AccessKey pair used by the CLI must have the AliyunAgentRunFullAccess permission. If a command returns AccessDenied or exit code 3, check this item first. For more information about how to grant permissions, see Grant RAM users access to AgentRun.

Configure a local profile

ar config set access_key_id     LTAI5t...
ar config set access_key_secret ***
ar config set account_id        1234567890
ar config set region            cn-hangzhou

The preceding settings are written to the default profile in ~/.agentrun/config.json. You can also create separate profiles for different environments:

ar config set access_key_id LTAI-staging --profile staging
ar config set region        cn-shanghai  --profile staging

ar --profile staging runtime list

You can also provide credentials by using environment variables, such as AGENTRUN_ACCESS_KEY_ID, AGENTRUN_ACCESS_KEY_SECRET, AGENTRUN_ACCOUNT_ID, and AGENTRUN_REGION.

Launch a Super Agent with a single command

Before you use ar super-agent commands, you must grant permissions to the AliyunAgentRunSuperAgentRole service-linked role in the RAM console. AgentRun uses this role, whose trusted entity is agentrun.fc.aliyuncs.com, to manage runtime resources. The following system policies are attached to the role:

  • AliyunAgentRunInvokeOnlyAccess (AgentRun invocation permissions)

  • AliyunAgentRunReadOnlyAccess (AgentRun read-only permissions)

Open the following authorization link and click One-click Authorization in the RAM console to create the role:

Create AliyunAgentRunSuperAgentRole

If the role does not exist, ar super-agent run or ar super-agent apply fails during the creation phase.

Note

If a RAM user does not have the ram:ListRoles permission, the user cannot complete the authorization. In this case, contact the Alibaba Cloud account administrator to create the role and grant the permissions.

Quickly create a managed agent in the terminal and start a conversation:

ar super-agent run --prompt "You are a Python expert"

The command creates a Super Agent and enters an interactive REPL. The terminal prints the agent name during creation in the super-agent-tmp-{timestamp} format, such as super-agent-tmp-20260420213045. To exit the REPL, enter /exit or press Ctrl+D. The agent is retained after you exit, and you can use its name to continue the conversation later:

ar sa chat super-agent-tmp-20260420213045

The short alias of super-agent is sa. Common commands:

Command

Description

ar sa run

Creates a Super Agent and enters an interactive conversation.

ar sa chat <name>

Connects to an existing Super Agent and resumes the previous session by default.

ar sa invoke <name> -m "..."

Performs a single invocation, which is suitable for scripts and CI pipelines.

ar sa apply -f superagent.yaml

Creates or updates a Super Agent from YAML.

ar sa delete <name>

Deletes a Super Agent.

If your script needs only the assistant's reply text, add --text-only:

ar sa invoke my-helper -m "Summarize today's alerts" --text-only

Declaratively manage a Super Agent in YAML

Write the agent configuration in YAML so that you can manage agents in the same way that you manage code:

apiVersion: agentrun/v1
kind: SuperAgent
metadata:
  name: my-helper
  description: "My assistant"
spec:
  prompt: "You are my capable assistant"
  tools:
    - mcp-time-sa
  skills: []
  sandboxes: []
  workspaces: []
  subAgents: []

Save the file as superagent.yaml and then run the following command:

ar sa apply -f superagent.yaml

The first run creates the agent, and subsequent runs update the agent that has the same name. You can separate multiple YAML documents with --- and deploy them at a time.

To check what request the YAML is rendered into without actually calling the server:

ar sa render -f superagent.yaml

Deploy an Agent Runtime from a container image

If your agent is already packaged as a container image, you can run ar runtime apply to deploy an Agent Runtime. The short alias of runtime is rt.

Minimal YAML:

apiVersion: agentrun/v1
kind: AgentRuntime
metadata:
  name: my-agent
spec:
  container:
    image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1

Deploy the runtime:

ar runtime apply -f runtime.yaml

After the deployment, run the following command to check whether the runtime is ready. The --wait parameter continuously polls until the runtime becomes ready or the operation times out:

ar rt status my-agent --wait

If spec.endpoints is omitted from the YAML, the CLI automatically injects an endpoint named default that points to the LATEST version. If cpu, memory, or port is not explicitly specified, the CLI also injects default values to prevent the backend from rejecting the request because of empty values. For the specific default values, refer to the user manual in the AgentRun CLI repository.

Build the image in the cloud

To build the image in the cloud before you deploy it, add cloudBuild under spec.container:

apiVersion: agentrun/v1
kind: AgentRuntime
metadata:
  name: my-agent
spec:
  container:
    image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1
    cloudBuild:
      dir: .
      setupScript: scripts/setup.sh
      baseContainerConfig:
        image: serverless-registry.cn-hangzhou.cr.aliyuncs.com/functionai/docker-image-builder-worker:20260514-111141-2d80effe

Build and deploy:

ar runtime apply -f runtime-build.yaml

Build only, without deploying:

ar runtime cloud-build -f runtime-build.yaml

Export an existing runtime to reusable YAML

If a runtime already exists in the console or in another process, you can use the CLI to export it to YAML:

ar runtime export my-agent -f copied-runtime.yaml

The exported YAML can be used directly with ar runtime apply. A common use is to copy a runtime:

ar runtime export my-agent -f copied-runtime.yaml
# Edit copied-runtime.yaml and change metadata.name to my-agent-copy
ar runtime apply -f copied-runtime.yaml

The export intentionally omits server-side state fields such as IDs, ARNs, versions, statuses, and timestamps. Sensitive fields such as image repository passwords are not exported by default. Use the following command only when you explicitly need a complete export:

ar runtime export my-agent --include-secrets
Warning

Review the exported YAML before you share it, commit it, or paste it into a ticket, to avoid leaking sensitive information.

Agents that are deployed and managed by the CLI also support integration and release. For more information, see Agent integration and publishing.

Output formats and exit codes

By default, the CLI outputs JSON, which makes it easy for scripts and automated agents to parse the results. You can also switch the output format by using a global parameter:

ar --output table runtime list
ar --output yaml runtime get my-agent
ar --output quiet runtime get my-agent

Common exit codes:

Exit code

Description

0

Success.

1

The resource does not exist or has entered a failed state.

2

Invalid parameter.

3

Authentication or permission failure.

4

Server error or request timeout.

5

Failed to create, update, or delete a runtime or an endpoint.

6

Polling exceeded --timeout.

130

Interrupted by the user.

Error messages are written to stderr, usually in JSON format, so that CI pipelines can determine the cause of a failure.

Command quick reference

Goal

Command

View the version

ar --version

Configure credentials

ar config set <key> <value>

View the current configuration

ar config list

Create a Super Agent and start a conversation

ar sa run --prompt "..."

Resume a conversation with a Super Agent

ar sa chat <name>

Invoke a Super Agent once

ar sa invoke <name> -m "..." --text-only

Deploy a Super Agent declaratively

ar sa apply -f superagent.yaml

Preview the Super Agent request

ar sa render -f superagent.yaml

Delete a Super Agent

ar sa delete <name>

Deploy a runtime

ar rt apply -f runtime.yaml

Build an image in the cloud

ar rt cloud-build -f runtime-build.yaml

Export a runtime

ar rt export <name> -f runtime.yaml

View the runtime status

ar rt status <name> --wait

Delete a runtime

ar rt delete <name> --yes

Best practices

  • For local debugging, use ar sa run or ar sa chat first, and write the YAML after you confirm the agent's behavior.

  • In production and CI scenarios, use apply and store the YAML in a code repository so that changes are auditable and reversible.

  • runtime export is suitable for migration and copying, but do not commit exported sensitive fields to a repository.

  • Place root-level global parameters before the command group. For example, use ar --profile staging rt list instead of ar rt list --profile staging.

  • In non-interactive scripts, use --output json or --output quiet to avoid parsing human-readable text.

References