Use commands such as list, connect, exec, and upload/download to query ECS instances, log on without a password, run remote commands, and transfer files. Structured JSON output and command exit code passthrough support script consumption and quick self-diagnosis of failures.
Prerequisites
Workbench CLI is installed on your computer, and credentials and the minimum RAM permissions are configured. For more information, see Install Workbench CLI and configure credentials.
The target ECS instance is a Linux instance in the Running state, and the Cloud Assistant agent is installed and running.
Your computer can access
*.aliyuncs.comand the Workbench backend WebSocket endpoint. Theuploadanddownloadcommands also require the instance to be able to access the OSS internal endpoint of the corresponding region.
Workbench CLI currently supports connecting only to Linux instances. To connect to a Windows instance, use Connect to an instance by using Workbench.
Global parameters
The following three global parameters apply to all workbench subcommands.
Parameter |
Default value |
Description |
|---|---|---|
|
|
The output format. Valid values: |
|
Inferred automatically |
The Alibaba Cloud region ID, such as |
|
The active profile |
Specifies the credential profile to use for this command, overriding the active profile. Use it to switch between multiple accounts or credential sets. |
The region is inferred in the following order: instance ID prefix mapping → lookup of active sessions in the daemon → an error that prompts you to specify --region manually. When you use an instance for the first time, we recommend that you run workbench list ecs -r <region> first to confirm the instance ID.
Query the instance list (workbench list ecs)
Use this command to query ECS instances by region, status, tag, and other conditions, so that you can quickly locate the target instance ID. workbench list is equivalent to workbench list ecs by default. Common examples:
# Query all instances in a specified region
workbench list ecs -r cn-hangzhou
# Query only running instances
workbench list ecs -r cn-hangzhou --status Running
# Filter by tag (multiple --tag options use AND semantics)
workbench list ecs -r cn-hangzhou --tag env=prod --tag app=web
# Filter by instance type, name, VPC, and other conditions
workbench list ecs -r cn-hangzhou --instance-type ecs.g7.large --instance-name "web-*"
# Output JSON for consumption by scripts or AI agents
workbench list ecs -r cn-hangzhou --output json
Parameters:
Parameter |
Required |
Description |
|---|---|---|
|
Yes |
The Alibaba Cloud region ID. |
|
No |
Filters by status. Valid values: |
|
No |
Filters by tag in the |
|
No |
Filters by instance type, for example, |
|
No |
Filters by instance name. The wildcard |
|
No |
Filters by image ID. |
|
No |
Filters by VPC ID. |
|
No |
Filters by zone ID. |
|
No |
Filters by vSwitch ID. |
|
No |
Filters by private IP addresses. Separate multiple addresses with commas. |
|
No |
The maximum number of instances to return per page. Valid values: 1 to 100. Default: 50. |
|
No |
The pagination token obtained from the previous response, used to retrieve the next page. |
The return structure of --output json is as follows:
{
"instances": [
{
"instance_id": "i-bp1xxxxx",
"instance_name": "web-prod-01",
"instance_type": "ecs.g7.large",
"region_id": "cn-hangzhou",
"status": "Running",
"private_ip": "172.16.0.10",
"public_ip": "",
"os_type": "linux",
"image_id": "aliyun_3_x64_20G_alibase_20230727.vhd",
"tags": {"env": "prod"}
}
]
}
Interactive connection (workbench connect)
workbench connect opens an interactive PTY session and is the core command of Workbench CLI. Common examples:
# Default no authentication (Workbench passwordless logon)
workbench connect -i i-bp1a2b3c4d5e6f
# Password authentication (enter the password interactively; input is not echoed)
workbench connect -i i-bp1a2b3c4d5e6f --auth-type password
# Certificate authentication (enter the key file path interactively, such as ~/.ssh/id_rsa)
workbench connect -i i-bp1a2b3c4d5e6f --auth-type certificate
# Specify the logon user and port
workbench connect -i i-bp1a2b3c4d5e6f -u admin -p 2222
# Force a new session (do not reuse an existing session)
workbench connect -i i-bp1a2b3c4d5e6f --new
Parameters:
Parameter |
Required |
Default value |
Description |
|---|---|---|---|
|
Yes* |
— |
The ECS instance ID. |
|
No |
Inferred automatically |
The Alibaba Cloud region ID. You typically do not need to specify it. |
|
No |
|
The remote logon username. |
|
No |
|
The authentication method. Valid values: |
|
No |
|
The remote SSH port. |
|
No |
|
Forces a new session and does not reuse an existing session. |
|
Yes* |
— |
Connects directly to a specified session ID (advanced usage). |
* Specify either -i or --session-id. If you specify both, --session-id takes precedence.
Authentication Methods
Authentication method |
Behavior |
Scenario |
|---|---|---|
|
Establishes a session directly through the Workbench passwordless logon channel, without the need to preset a password or key on the instance. |
Daily O&M with no SSH key management overhead. |
|
Prompts you to enter the password interactively after connecting. Input is not echoed. |
Scenarios where the instance has password logon enabled and requires SSH password authentication. |
|
Prompts you to enter the key file path interactively after connecting (such as |
Scenarios where the team requires key-based logon and auditing must trace back to the key fingerprint. |
Interactive Commands and Shortcut Keys
After you enter a workbench connect session, press Tab at the start of a line to bring up the slash command panel:
Command |
Function |
|---|---|
|
Enters the in-session AI agent conversation mode (see the next section). |
|
Uploads a local file to the instance (opens an interactive file picker). |
|
Downloads a file from the instance to the local computer (opens an interactive file picker). |
|
Detaches the session (the session stays active in the background, and you can reattach to it later by running |
|
Exits and closes the session. |
|
Clears the screen. |
|
Displays help information. |
Common shortcut keys:
Key |
Function |
|---|---|
|
Brings up the slash command panel. |
|
Enters or exits AI agent mode. |
|
Exits the session (equivalent to |
|
Interrupts the current remote command without disconnecting the session. |
Use the In-Session AI Agent Assistant
Within a workbench connect session, you can directly invoke the built-in AI agent assistant to have the AI perform operations on the current instance using natural language. You can trigger it in the following three ways:
Enter
/agentat the start of a line and press Enter.Press the
Ctrl+Ashortcut key.Press
Tabto bring up the slash command panel and select/agent.
After you enter agent mode, the command prompt changes to a dedicated agent-mode prompt. Enter natural language directly after this prompt, and the agent returns responses as a stream. Slash commands in agent mode:
Command |
Function |
|---|---|
|
Exits agent mode and returns to the regular shell (Ctrl+A also exits). |
|
Starts a new agent conversation and clears the context. |
|
Clears the screen. |
|
Triggers a file upload or download directly within agent mode. |
|
Displays help. |
|
Exits and closes the session. |
A typical conversation example:
Agent> Show the processes with the highest CPU usage
┌─ Running command ──────────
│ ps aux --sort=-%cpu | head -10
└────────────────────────
Waiting for confirmation (Y/n): y
[Executed]
... (the agent continues its analysis and provides conclusions)
Human-in-the-loop (HITL) confirmation: Before the agent runs any command on the instance, it displays the command to be run and waits for you to confirm with Y/n. Cloud API operations (such as creating a snapshot) also require confirmation. This is a key mechanism to prevent unintended actions by the AI. Do not disable it.
The agent retains the conversation context within the same session. You can use /new to reset it. Responses are streamed, and you can press Ctrl+C to interrupt the current generation.
This section describes how to directly invoke the built-in AI assistant within a connect session. If you want an agent in an external AI programming tool (Wukong or opencode) to call workbench commands, see Operate ECS instances by using Workbench CLI in AI agents.
Remote command execution (workbench exec)
workbench exec runs a single command on the instance and returns the result. Unlike the persistent shell of connect, each exec call runs in an independent environment. Multiple calls to the same instance reuse the underlying connection channel, so no repeated connection setup is needed. Common examples:
# Run a command
workbench exec -i i-bp1a2b3c4d5e6f -c "df -h"
# Combine commands: cd + environment variable + run
workbench exec -i i-bp1a2b3c4d5e6f -c "cd /opt/app && ./deploy.sh"
# Set a timeout
workbench exec -i i-bp1a2b3c4d5e6f -c "sleep 30" --timeout 10
# JSON output for consumption by scripts or AI agents
workbench exec -i i-bp1a2b3c4d5e6f -c "df -h" --output json
Parameters:
Parameter |
Required |
Default value |
Description |
|---|---|---|---|
|
Yes |
— |
The ECS instance ID. |
|
Yes |
— |
The command to run. |
|
No |
|
The timeout period, in seconds. |
Each exec call runs in an independent shell environment and does not inherit the current directory, environment variables, or shell state from the previous call. If you need context continuity (for example, run cd and then run another command), combine the commands with && or ; in the same -c parameter.
The return structure of --output json is as follows:
{
"output": "Filesystem ...\n",
"stderr": "",
"exit_code": 0
}
In this structure, output is the standard output of the command, stderr is the standard error, and exit_code is the exit code of the remote command (an integer).
File transfer (workbench upload / download)
When you do not have a public IP address or an SCP channel, use workbench upload / workbench download to transfer files. The upload process displays a real-time progress bar.
Upload example:
workbench upload ./app.jar /opt/app/app.jar -i i-bp1a2b3c4d5e6f
Download example:
# Download to the current directory
workbench download /var/log/app.log ./ -i i-bp1a2b3c4d5e6f
# Download and rename
workbench download /var/log/app.log ./local-copy.log -i i-bp1a2b3c4d5e6f
Parameters:
Parameter |
Required |
Default value |
Description |
|---|---|---|---|
|
Yes |
— |
The ECS instance ID. |
Files are transferred by being relayed through OSS, which is completely transparent to you and requires no OSS permission or bucket configuration. The instance must be able to access the OSS internal endpoint of the corresponding region (oss-<region>-internal.aliyuncs.com).
Session management (workbench session)
Sessions are usually created, reused, and cleaned up automatically by the CLI, and require no intervention in daily use. The commands in this section are used for diagnosis and manual cleanup.
Common commands:
# View all active sessions
workbench session list
workbench session list --output json
# Close a specified session
workbench session close <session-id>
# Close all sessions
workbench session close --all
Session state transitions:
OPEN: The session is established and can be read from and written to normally.RECONNECTING: The underlying WebSocket has disconnected and is reconnecting.BROKEN: Reconnection failed and the session is unavailable.CLOSED: The session is closed (closed by the user, timed out, or reached the TTL limit).
Multiple connect, exec, upload, and download operations on the same instance share the same session, which is handled transparently by the daemon, so you do not need to be concerned about the session ID. Only one terminal (TTY) can attach to the same session at a time. If a terminal is already attached, you can use --new to create a new session, or close the existing connection first.
Daemon management (workbench daemon)
Workbench CLI relies on a user-space background daemon to hold the WebSocket connection and multiplex sessions. The lifecycle of the daemon is fully automatic and usually requires no manual management.
# View the daemon status
workbench daemon status
# Stop the daemon (closes all sessions)
workbench daemon stop
Automatic startup: The daemon is started automatically the first time you run any
workbenchcommand.Automatic exit: The daemon exits automatically 60 seconds after the last session is closed.
Single instance: Only one daemon instance is allowed per operating system user (enforced by a PID file lock).
IPC channel: The CLI and the daemon communicate through
~/.workbench/run/daemon.sock(a Unix socket), using the JSON-RPC protocol.
Typical scenarios
Scenario 1: Application Deployment
Upload the deployment package → run the deployment script remotely → verify service health on the instance.
workbench upload ./app-2.0.tar.gz /opt/deploy/ -i i-bp1a2b3c4d5e6f
workbench exec -i i-bp1a2b3c4d5e6f -c "cd /opt/deploy && tar xzf app-2.0.tar.gz && ./deploy.sh"
workbench exec -i i-bp1a2b3c4d5e6f -c "curl -s http://localhost:8080/health"
Scenario 2: Batch Execution of Diagnostic Commands
Use exec --output json to obtain structured results for further parsing by a script or filtering with jq.
workbench exec -i i-bp1a2b3c4d5e6f -c "df -h && free -m" --output json | jq '.output'
workbench exec -i i-bp1a2b3c4d5e6f -c "systemctl status nginx" --output json | jq '.exit_code'
Scenario 3: Reattach to a Session After Detaching
For long-running tasks (such as log tailing or compilation), you can run /detach and then close the local terminal. When you run connect again later, you automatically reattach to the original session.
workbench connect -i i-bp1a2b3c4d5e6f
# Run tail -f or a long-running task in the session
# Then enter /detach to detach
# Reattach to the original session later
workbench connect -i i-bp1a2b3c4d5e6f
Exit codes
workbench exec passes through the exit code of the remote command: whatever exit code the remote command returns, the CLI exits with the same exit code (consistent with SSH behavior). Therefore, a script can determine whether the remote command succeeded directly from the exit code of workbench exec.
For example, the following command runs exit 42 on the instance, and the CLI also exits with 42:
workbench exec -i i-bp1a2b3c4d5e6f -c "exit 42"
echo $? # Outputs 42
When a command fails due to reasons such as parameters, authentication, network, or a nonexistent instance, using --output json outputs the error details in the following format:
{
"code": 1,
"message": "session resolve: login instance: ... InvalidParameter.InstanceId ..."
}
In this structure, code is a non-zero error identifier, and message is a readable error description (which usually includes the error code and RequestId of the underlying API), which you can use to locate the issue.
Troubleshooting
Common symptoms and the first action to take:
Symptom / error message |
First action |
|---|---|
Authentication failure / | Check whether the AccessKey ID and AccessKey secret in |
An error indicating that the instance does not exist / | Confirm that the instance ID and region are correct. You can run |
Passwordless logon fails / | By default, passwordless logon (when |
| Check whether the profile name is correct. Run |
Connection timeout / WebSocket error | Check whether your computer can access |
Connection is occupied (the session is already attached by another terminal) | Use |
Cannot connect to the daemon | Run |
Configuration file permission error | Run |
STS token expired | In RamRoleArn mode, the CLI refreshes automatically. If you use a static STS token, update the token. |
Debugging commands:
# View the daemon status
workbench daemon status
# JSON error output for easy parsing by scripts
workbench exec -i i-bp1a2b3c4d5e6f -c "echo test" --output json
The daemon logs are saved in ~/.workbench/log/daemon.log.
References
Connect to an instance by using Workbench CLI: the parent topic, which covers the tool's positioning and quick start.
Install Workbench CLI and configure credentials: CLI installation and credential/permission configuration.
Operate ECS instances by using Workbench CLI in AI agents: have an agent call workbench commands in Wukong or opencode.
Install the Cloud Assistant agent: Workbench CLI depends on the Cloud Assistant agent.