Manage the full lifecycle of Data Science Workshop (DSW) interactive modeling instances.
instance create
pai dsw instance create --name NAME [flags]Parameter | Type | Default | Description |
| string | — | Instance name. Required. |
| string | — | Image ID (mutually exclusive with --image-url). |
| string | — | Image repository URL (mutually exclusive with --image). |
| string | — | Base64-encoded authentication for private images. |
| string | — | Pay-as-you-go: ECS instance type, such as ecs.gn7i-c8g1.2xlarge. |
| string | — | Subscription: resource quota ID. |
| string | — | Subscription: number of CPU cores. |
| string | — | Subscription: memory size, such as 8GB. |
| int | — | Subscription: number of GPUs. |
| string | — | Subscription: GPU model, such as V100, A100, or T4. |
| string | — | Subscription: shared memory size, such as 8GB. |
| int | — | Subscription: scheduling priority from 1 (lowest) to 9 (highest). |
| string | — | Overselling policy: |
| string | config | Workspace ID. |
| stringArray | — | Dataset mount in the format id:mount_path[:version]. Can be specified multiple times. |
| string | — | Dataset JSON array (API field format). |
| string | — | Cloud disk capacity, such as 100Gi. Mutually exclusive with --cloud-disks. |
| string | — | Cloud disk configuration JSON array. |
| stringArray | — | Environment variables in KEY=VALUE format. Can be specified multiple times. |
| stringArray | — | Instance labels in KEY=VALUE format. Can be specified multiple times. |
| stringArray | — | Instance tags in KEY=VALUE format. Can be specified multiple times. |
| string | — | Script to run on each startup. |
| string | — | UserCommand JSON (mutually exclusive with --startup-script). |
| int | — | Idle timeout in minutes before automatic shutdown. |
| string | — | NVIDIA driver version, such as 535.230.02. |
| string | — | Instance visibility: |
| string | — | SSH public key. Enables SSH access when set. |
| string | — | SSH access types, comma-separated: intranet, internet. |
| string | 22 | SSH listening port. |
| string | Auto | SSH port mapped to the public network. |
| string | — | Elastic IP Address (EIP) ID for SSH (used with NAT gateway). |
| string | — | NAT gateway ID. |
| string | — | NLB gateway ID (mutually exclusive with NAT/EIP). |
| string | — | VPC network configuration JSON. |
| string | — | Pay-as-you-go: spot instance configuration JSON. |
| stringArray | — | Custom service/port forwarding configuration. Can be specified multiple times. |
| string | — | Scheduling affinity configuration JSON. |
| string | — | Node scheduling configuration JSON. |
| string | — | Instance credential configuration JSON. |
| string | — | Docker configuration JSON. |
| string | — | Dynamic mount configuration JSON. |
| string | — | Instance migration options (Lingjun + persistent storage scenario). |
| string | — | Working directory storage source. |
| bool | false | Print the assembled request body in PascalCase (matching the API format) without creating an instance. Use with --body-json to reuse the template. |
| string | — | Complete request body JSON (overrides all above options). |
| bool | false | Output a JSON request template and exit. Use to generate a --body-json template. |
| stringArray | — | Modify request body fields before submission. See --override request body editing. |
Examples
# 1. Pay-as-you-go: minimal creation (ECS spec + image)
pai dsw instance create \
--name my-instance \
--ecs-spec ecs.gn7i-c8g1.2xlarge \
--image pytorch:2.0.1-gpu-py310-cu118-ubuntu20.04
# 2. Subscription: use resource quota (use cpu/gpu/memory, not ecs-spec)
pai dsw instance create \
--name my-prepaid \
--resource-id quota-a1b2c3d4e5f6 \
--cpu 8 --memory 16GB --gpu 1 --gpu-type A100 \
--image pytorch:2.0.1-gpu-py310-cu118-ubuntu20.04
# 3. Mount dataset + idle auto-shutdown (shuts down after 60 minutes of inactivity)
pai dsw instance create \
--name my-instance \
--ecs-spec ecs.gn7i-c8g1.2xlarge \
--image pytorch:2.0.1-gpu-py310-cu118-ubuntu20.04 \
--dataset d-abc123:/mnt/data \
--idle-timeout 60
# 4. Enable SSH remote access
pai dsw instance create \
--name my-instance \
--ecs-spec ecs.gn7i-c8g1.2xlarge \
--image pytorch:2.0.1-gpu-py310-cu118-ubuntu20.04 \
--ssh-public-key "ssh-rsa AAAA..." \
--ssh-access-type internet
# 5. --generate-skeleton to generate a request template (for --body-json advanced configuration)
pai dsw instance create --generate-skeleton > instance.json
# Edit instance.json and then submit
pai dsw instance create --body-json "$(cat instance.json)"instance list
pai dsw instance list [flags]Parameter | Type | Default | Description |
| string | config | Workspace ID. |
| string | — | Filter by status |
| string | — | Sort order: |
| int | 1 | Page number. |
| int | 20 | Items per page. |
| string | — | Custom output columns, comma-separated. Default: instance_id, instance_name, status, payment_type, ecs_spec, image_id, workspace_id, gmt_create_time, gmt_modified_time. |
instance get
pai dsw instance get <instance-id> [--all] [--raw] [--show-secrets]Parameter | Type | Default | Description |
| bool | false | Show all fields in table view (json/yaml output always includes all fields). |
| bool | false | Display service passwords and image repository credentials in plaintext. By default, only |
| bool | false | Output the raw API response: credentials as-is, with HTTP envelope, and unset API fields omitted instead of null. |
instance update
pai dsw instance update <instance-id> [flags]Update instance properties. Uses patch semantics: only specified fields are sent. Unspecified fields retain their current values. To remove a configuration, use the corresponding --remove-* flag (requires confirmation).
Parameter | Type | Default | Description |
| — | No change | Replace the corresponding field (same meaning as create). |
| stringArray | No change | Replace the entire configuration group (not incremental). |
| bool | false | Remove the corresponding configuration. Requires confirmation (or add |
| string | — | Complete UpdateInstance request body (PascalCase). Supports |
| stringArray | — | Modify request body fields before submission. See --override request body editing. |
| bool | false | Print the request body without sending. |
| bool | false | Skip confirmation prompts for --remove-*. |
instance apply / save / render — declarative management
Manage instances through configuration files (kubectl-style workflow): save exports a running instance configuration → edit → render validates offline → apply creates or updates.
pai dsw instance save <instance-id> [--out FILE] [--format yaml|json] [--force]
pai dsw instance render -f <file>
pai dsw instance apply -f <file> [--dry-run] [--prune] [-y]Parameter | Type | Default | Description |
| string | stdout | Write to file. Refuses to overwrite existing files unless |
| string | yaml | Export format: |
| string | — | Instance configuration file (JSON/YAML). Use |
| string | Lookup by name | Specify the target instance directly, skipping lookup. Overrides InstanceId in the file. |
| bool | false | Compare with the running instance and show what would be created or changed. Outputs |
| bool | false | Remove configurations not declared in the file (datasets, environment variables, VPC, driver, etc.). Requires confirmation. |
| stringArray | — | Modify configuration fields before applying. See --override request body editing. |
# 1. Export the running instance configuration (only fields accepted by the create request; credentials are never written)
pai dsw instance save dsw-xxxx --out instance.yaml
# 2. Validate offline after editing (no API calls or credentials needed; can run in CI)
pai dsw instance render -f instance.yaml
# 3. Preview changes and then apply
pai dsw instance apply -f instance.yaml --dry-run
pai dsw instance apply -f instance.yaml
# Pipeline: export and validate in one step
pai dsw instance save dsw-xxxx | pai dsw instance render -f -apply locates the target instance by name in the configuration: creates it if it doesn't exist, updates it if it does, and sends no request if there are no changes (idempotent). Suitable for managing instance configurations in Git.
instance delete
pai dsw instance delete <instance-id> [-y] [--dry-run]Parameter | Type | Default | Description |
| bool | false | Skip confirmation prompts (required for scripting and automation). |
| bool | false | Preview the operation without executing. |
If the deleted instance is the current context set by instance use, the CLI automatically clears that context to prevent subsequent commands from targeting a nonexistent instance.
instance start / stop
pai dsw instance start <instance-id> [--dry-run]
pai dsw instance stop <instance-id> [--dry-run]Parameter | Type | Default | Description |
| bool | false | Preview the operation without executing. |
instance wait
pai dsw instance wait <instance-id> --for <status>Parameter | Type | Default | Description |
| string | — | Target status. Required: |
| int | 5 | Polling interval in seconds. |
| int | 300 | Maximum wait time in seconds. |
instance exec
pai dsw instance exec [instance-id] [-- command...]Parameter | Type | Default | Description |
| string | — | Execute a Python code snippet. |
| string | — | Upload a local file to the instance and execute it. |
| string | /tmp/dsw_exec_<name> | Remote upload destination (trailing / indicates a directory). |
| string | — | Remote working directory. |
| int | 120 | Command execution timeout in seconds. |
| string | gateway | Data plane channel: |
Wrap commands that contain pipes or redirections in quotes: pai dsw instance exec -- "ls -la | grep model"
Examples
# 1. Run a shell command (with pipe, must be quoted)
pai dsw instance exec -- "ls -la /workspace | grep .pt"
# 2. Execute a Python code snippet
pai dsw instance exec --code "import torch; print(torch.cuda.is_available())"
# 3. Upload and run a local script on the instance
pai dsw instance exec --file ./train.py
# 4. Specify remote working directory and timeout
pai dsw instance exec --cwd /workspace --timeout 600 -- "python eval.py"
# 5. Upload a script to a specific path and run it
pai dsw instance exec --file ./test.py --remote-path /workspace/test.py
# 6. Execute through VPC channel (when the instance has no public network access)
pai dsw instance exec --via vpc -- "nvidia-smi"instance cp
pai dsw instance cp <src> <dst> [flags]Upload: pai dsw instance cp ./local.txt dsw:/workspace/file.txt
Download: pai dsw instance cp dsw:/workspace/out.csv ./
Parameter | Type | Default | Description |
| string | Current context | Target instance ID (required when no context is set). |
| string | gateway | Data plane channel: |
| bool | false | Preview the operation without executing. |
Examples
# 1. Upload a local file to the instance
pai dsw instance cp ./train.py dsw:/workspace/train.py
# 2. Download a file from the instance to local
pai dsw instance cp dsw:/workspace/model.pt ./
# 3. Upload an entire directory
pai dsw instance cp ./data/ dsw:/workspace/data/
# 4. Specify the instance when no context is set
pai dsw instance cp ./config.yaml dsw:/workspace/ --instance i-xxxxxxxx
# 5. Transfer through VPC channel
pai dsw instance cp ./large-file.bin dsw:/workspace/ --via vpc
# 6. Preview the operation (no actual transfer)
pai dsw instance cp ./train.py dsw:/workspace/train.py --dry-runinstance logs
pai dsw instance logs [instance-id] [flags]Parameter | Type | Default | Description |
| bool | false | Continuously follow the event stream (similar to tail -f). |
| string | — | Show only events after the specified time (e.g., 30m, 2h, 3d). |
| int | 2000 | Maximum number of events to return. |
instance metrics
pai dsw instance metrics <instance-id> --metric <NAME> [flags]Read CloudMonitor metrics for an instance, such as CPU/GPU utilization, memory, and disk. Use --list-metrics to view the available metric catalog.
Metrics return data only for subscription instances. Pay-as-you-go instances return an empty sequence (the API succeeds but with no data). The CLI checks the billing type and shows a clear message — otherwise an empty table looks like the instance is idle.
Parameter | Type | Default | Description |
| string | — | CloudMonitor metric name. Required (or use --list-metrics to browse the catalog). |
| bool | false | Print the metric catalog and exit. |
| string | -1h / now | Time window: RFC3339 or relative offset (e.g., -90m, -6h, -2d). |
| string | 60 | Sampling interval in seconds. Supported values: |
| int | 1440 | Maximum data points per page (API limit: 1440). |
| string | — | Pagination token (from the next_token field in |
| string | Auto-built | Override CloudMonitor dimension JSON. For example, add a "gpu" dimension to limit CARD_* metrics to a single GPU. Not needed for typical use. |
| string | acs_pai_dsw | CloudMonitor namespace. Usually doesn't need to be changed. |
# List available metrics
pai dsw instance metrics dsw-xxxx --list-metrics
# GPU memory utilization for the last hour
pai dsw instance metrics dsw-xxxx --metric INSTANCE_GPU_ACCELERATOR_MEMORY_UTIL
# Specify time window and sampling interval (5-minute granularity)
pai dsw instance metrics dsw-xxxx --metric INSTANCE_CPU_UTIL \
--start 2026-08-16T00:00:00Z --end 2026-08-16T06:00:00Z --period 300CARD_* metrics produce one time series per GPU (distinguished by the gpu column). A 16-GPU instance generates 16 rows per time point. The API paginates by GPU: when a long time window hits the limit, it keeps all timestamps but drops entire GPUs, making results look complete when they're not. The CLI reports this as truncated — shorten the window or increase --period to see all data.
instance sanity-check
pai dsw instance sanity-check <instance-id> [--type ssh] [flags]Run a health check on an instance and wait for the result. The check is an asynchronous task: by default, the CLI creates the task and polls until it reaches a terminal state. Use --async to get only the task ID and return immediately, then use --task-id to read the result later.
Parameter | Type | Default | Description |
| string | ssh | Check type. Known value: |
| bool | false | Return the task ID immediately without waiting for the result. |
| string | — | Read the result of an existing task (mutually exclusive with --async). |
| bool | false | Return per-checkpoint details (without this flag, only issues are returned). |
| int | 5 / 300 | Polling interval and maximum wait time in seconds. |
instance use / current
pai dsw instance use <instance-id> [--via gateway|vpc|internet] [--force]
pai dsw instance currentParameter | Type | Default | Description |
| string | gateway | Set the default data plane channel. |
| bool | false | Set the context even if the VPC or Internet channel is unreachable. |
After setting the context, subsequent exec, cp, and rootfs-usage commands can omit the instance ID.
instance list-ecs-specs
pai dsw instance list-ecs-specs --accelerator-type <CPU|GPU>Parameter | Type | Default | Description |
| string | — | Accelerator type. Required: |
| string | — | Sort field. |
| string | — | Sort order: |
| int | 1 | Page number. |
| int | 100 | Items per page. |
| string | — | Custom output columns. Default: instance_type, accelerator_type, cpu, memory, gpu, gpu_type, gpu_memory_size, is_available. |
instance rootfs-usage
pai dsw instance rootfs-usage [instance-id] [flags]Analyze the disk usage of the instance root filesystem. Automatically excludes mounted datasets, cloud disks, and non-system paths such as /mnt/workspace.
Parameter | Type | Default | Description |
| string | / | Root path for analysis. |
| int | 2 | Directory display depth. |
| stringArray | — | Additional paths to exclude. Can be specified multiple times. |
| bool | true | Show the excluded paths in the output. |
| int | 5 | Scan polling interval in seconds. |
| int | 300 | Maximum wait time in seconds. |
| string | gateway | Data plane channel: |
instance mcp-config
pai dsw instance mcp-config [instance-id] [--via internet|vpc]Output standard mcpServers JSON configuration that can be pasted directly into MCP-compatible clients such as Cursor or Claude Code.
Parameter | Type | Default | Description |
| string | internet | Address type to use: |
instance proxy
pai dsw instance proxy start [instance-id] [--port 9806] [-d]
pai dsw instance proxy stop [instance-id] [--all]
pai dsw instance proxy listStart a local HTTP proxy that forwards MCP traffic to a DSW instance. MCP clients connect to http://localhost:<port>/mcp. No Alibaba Cloud credentials are required.
Parameter | Type | Default | Description |
| int | 9806 | Local listening port. |
| bool | false | Run the proxy process in the background. |
| bool | false | Stop all running proxies. |