Important Notes:
- All scripts in the
scriptsdirectory have implemented all functions. Do not create additional py/sh files. - Do not modify the script files in the
scriptsdirectory. - Please operate directly according to the provided code and documentation. No need to check Huawei Cloud official API documentation.
- All script files (
.sh,.py) first line must be a valid shebang (#!/bin/bashor#!/usr/bin/env python3), never insert comment lines before the shebang. - All Python scripts must use UTF-8 without BOM encoding. Windows editors may default to UTF-8 with BOM, causing
SyntaxErroron the shebang line. - Use
python -m pip installinstead ofpip installto avoid Windows PATH issues. - NEVER use
chmod 777in any script or documentation — security scan DES002 will block deployment. Usechown -R 1000:1000 <dir>followed bychmod 750 <dir>for restrictive permissions.
security Execution Rules (Highest Priority):
- All scripts MUST be executed via skill action=exec, NEVER run directly in shell
- NEVER print script contents or commands containing AK/SK/Token in conversation
- NEVER create temporary script files, prefer inline execution (python -c)
- On execution failure, only return error info, do NOT rewrite scripts or print full commands
- AK/SK/Token MUST be passed via environment variables, NEVER appear in conversation
- ABSOLUTELY NEVER expose, log, or print AK/SK/Token values in any form
- Scripts MUST NOT provide --ak, --sk, --token command-line parameter entry points. Credentials are read exclusively from environment variables (os.environ.get).
- NEVER check, detect, ask, prompt, or hint for AK/SK/Token at any point during deployment. Credentials are assumed to be already configured in environment variables. Do NOT run commands like
echo $HW_ACCESS_KEYorGet-ChildItem Env:to check credentials. If scripts fail due to missing credentials, simply report the error — do NOT ask the user to provide credentials. - NEVER use
chmod 777in scripts or documentation — security scan DES002 will block deployment. Usechown -R 1000:1000 <dir>to set ownership to container user UID, thenchmod 750 <dir>for restrictive access. - Docker socket access is restricted via docker-socket-proxy. The OpenHands container does NOT mount
/var/run/docker.sockdirectly. Instead, adocker-socket-proxyservice whitelists only the Docker API endpoints needed (containers, exec, images). This prevents the container from gaining host-root-equivalent access through the full Docker API.
Interaction Rules (Avoid Reload Cycles)
Avoid Reload Cycles After User Interaction
After each user response via ask_user, do NOT repeat the following reload sequence:
memory_search(search skill memory)skill_tool(reload skill)ttse_consult(repeatedly consult experience)
Correct approach: After the initial load, all context is already in the conversation. Proceed directly with bash or ask_user for the next step. Only execute the above load steps on first deployment startup or when the user explicitly requests a restart.
This applies to ALL interactions: region/flavor selection, confirmation, resource mode selection, or any ask_user response — proceed to the next phase immediately. Reloading after every response wastes tokens, causes repeated questions, and loses prior selections.
Credential detection must NEVER be part of any reload or checklist sequence. Do not list "Credential environment variable detection" as a step — listing it causes the agent to actively detect and prompt for credentials.
Script Execution Feedback
- When executing deployment scripts, always display script stdout/stderr output to the user in real-time — never run scripts silently and only show results after completion.
- For long-running operations (COC tasks, Docker pulls), provide periodic progress updates so the user knows the process is alive.
- If a script fails, immediately show the full error output in a code block with a clear header (e.g.,
Error Output:) before any analysis or next steps. - Do not summarize errors vaguely — show the actual error lines from the script output so the user can see the real failure reason.
Function Signature Confirmation Before Calling Scripts
- Before calling any function in the
scriptsdirectory, first useread_fileto view the target function's parameter definitions. - Common function signature:
do_set_security_group_rule(ak, sk, region, security_token, group_name, security_group_id, port) - For
deploy_openhands_via_coc, the region parameter name isregion_id(notregion). Other key parameters:resource_id(instance ID),script_content(script content),timeout(timeout duration). - Avoid parameter mismatches that cause repeated
edit_filedebugging, wasting interaction rounds.
Windows Environment Compatibility
- The execution environment may be Windows (e.g.,
D:\Tools\path). Avoid using Linux-specific commands such assleep. - For waiting/delay, use
python -c "import time; time.sleep(N)"instead ofsleep Nto ensure cross-platform compatibility. - Windows
TIMEOUTcommand syntax differs from Linux — do not use it as a direct replacement. - For Python timeout handling, use
threading.Timerorsubprocess.run(timeout=N)instead ofsignal.alarm/signal.SIGALRM(not available on Windows).
OpenHands Deployment Skill for Huawei Cloud Flexus L Instance
Overview
This skill deploys OpenHands on Huawei Cloud Flexus L instances via Docker Compose with intelligent dynamic resource allocation. It supports two deployment paths:
- Path A — Buy a new L instance and deploy: Call
create_flexus_l_instanceto purchase a Flexus L instance (Ubuntu 24.04), then chain-calldeploy_openhands_via_cocwithresource_mode=dedicated(90% resources). - Path B — Deploy on an existing server: User provides an existing Flexus L instance, skip instance creation, directly call
deploy_openhands_via_cocwith user-selectedshared(60%) ordedicated(90%) mode.
Both paths ultimately use COC script delivery to push openhands.sh to the target instance. The script automatically: detects host resources, installs/upgrades Docker, configures domestic mirrors, pulls images from multiple sources, generates production-grade docker-compose.yaml and .env, and starts OpenHands.
Based on the official OpenHands deployment command:
docker run -it --rm -p 8000:8000 \
-v "$HOME/.openhands:/home/openhands/.openhands" \
-v "$PROJECTS_PATH:/projects" \
ghcr.io/openhands/agent-canvas:1.35.0
Prerequisites
1. Huawei Cloud Account Requirements
- A valid Huawei Cloud account with active subscription
- Sufficient balance for subscription (Flexus L is prePaid only)
- Flexus L instance quota available in target region
2. IAM Credentials
- Huawei Cloud Access Key (AK) and Secret Key (SK) with appropriate permissions
- Temporary Security Credentials (STS Token): Supports temporary security credentials. When
HW_SECURITY_TOKENenvironment variable is set along with AK/SK, the skill will use temporary credentials for authentication. - Required IAM permissions:
hcss:lightInstances:*,coc:commands:*,iam:projects:list,vpc:securityGroupRules:* - See references/iam-policies.md for detailed policy configuration
- Credentials are read silently from environment variables; the agent MUST NOT check, detect, or ask for them at any phase.
3. Environment Requirements
- Python 3.8+ installed with pip
- It is recommended to use a Python virtual environment to avoid system package conflicts:
python3 -m venv .venv && source .venv/bin/activate - Required Python SDK packages:
huaweicloudsdkcore,huaweicloudsdkcoc,huaweicloudsdkvpc,huaweicloudsdkecs,requests,pyyamlpython -m pip install huaweicloudsdkcore huaweicloudsdkcoc huaweicloudsdkvpc huaweicloudsdkecs requests pyyaml
4. Network Requirements
- Internet access to Huawei Cloud APIs
- Domestic China: Script auto-configures 7 Docker Hub mirrors + DNS in
/etc/docker/daemon.json - Port 8000 available for OpenHands Web UI (open in security group after deployment)
- Outbound access to LLM API endpoints
5. Resource Requirements
- Flexus L instance with minimum specifications:
- Flavor: 2U4G (2 vCPUs, 4GB RAM) or higher; 4U8G+ recommended for dedicated mode
- Network: Public IP required (auto-provisioned with EIP)
- Supported flavors (Ubuntu 24.04):
| Flavor Code | CPU | RAM | System Disk | Bandwidth | Traffic Package |
|---|---|---|---|---|---|
hf.medium.1.linux |
2U | 4G | 70GB | 5Mbps | 1000GB |
hf.medium.2.linux |
2U | 4G | 80GB | 6Mbps | 1200GB |
hf.medium.3.linux |
2U | 4G | 100GB | 8Mbps | 1200GB |
hf.large.1.linux |
2U | 4G | 120GB | 10Mbps | 2000GB |
hf.xlarge.1.linux |
4U | 8G | 180GB | 6Mbps | 1200GB |
hf.xlarge.3.linux |
4U | 16G | 180GB | 10Mbps | 2000GB |
Note: Flexus L instances bundle system disk + EIP bandwidth + traffic package. Network (VPC/subnet/SG) is auto-provisioned.
6. Configuration Requirements
- LLM provider API keys for OpenHands AI agent functionality (configured post-deployment via Web UI Settings, never stored in .env)
- Optional:
OPENHANDS_RESOURCE_MODEfor resource allocation mode selection - OS compatibility:
openhands.shis tested on Ubuntu 24.04. Other Linux distributions (CentOS/RHEL/Alpine/etc.) may fail due to SELinux, firewalld, or package manager differences. Path A (new instance) defaults to Ubuntu 24.04 and is unaffected.
Architecture Diagram
┌─────────────────────────────────────────────────────────────┐
│ Host System Resources │
├─────────────────────────────────────────────────────────────┤
│ │
│ Mode = shared (default, co-resident): │
│ ┌───────────────────┐ ┌───────────────────┐ │
│ │ OpenHands Service │ │ OpenHands Sandbox │ │
│ │ (20% CPU/Mem) │ │ (40% CPU/Mem) │ │
│ └───────────────────┘ └───────────────────┘ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ System Reserved (40%) │ │
│ │ OS + Docker Daemon + other co-resident services │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Mode = dedicated (exclusive): │
│ ┌───────────────────┐ ┌───────────────────┐ │
│ │ OpenHands Service │ │ OpenHands Sandbox │ │
│ │ (30% CPU/Mem) │ │ (60% CPU/Mem) │ │
│ └───────────────────┘ └───────────────────┘ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ System Reserved (10%) │ │
│ │ OS + Docker Daemon (no co-resident services) │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Component Description:
- User/Agent: Skill caller that triggers OpenHands deployment operations via natural language or CLI
- Flexus L Instance: Huawei Cloud Flexus L server (Ubuntu 24.04), serving as the target host
- OpenHands Service: Main container running Agent Canvas + Web UI + API Server on port 8000
- OpenHands Sandbox: Sandbox containers created via Docker socket for code execution
- Resource Allocation: 60% shared (co-resident) or 90% dedicated (new instance), controlled by
OPENHANDS_RESOURCE_MODEenv var
Skill Responsibilities
Core Functions
- Flexus L Instance Creation - Call HCSS API to create instances with 6 flavor options, auto-provisioned network
- Instance Status Query - List all Flexus L instances in a region via
caller.py list - COC Remote Deployment - Use COC to remotely deliver and execute the OpenHands deployment script on instances
- Docker Auto-Install/Upgrade - Detects Docker presence and version; auto-installs or upgrades if missing or outdated
- Domestic China Mirror Configuration - Auto-configures 7 domestic Docker Hub mirrors + DNS settings in
daemon.json - Dynamic Resource Allocation - Two modes: shared (60% co-resident) or dedicated (90% exclusive); auto-detects host resources
- Security Group Management - Asks user for confirmation and source CIDR before opening port 8000 (does NOT default to 0.0.0.0/0)
- Public IP Retrieval - Auto-retrieves instance public IP via COC script execution and outputs access URL
- OpenHands Lifecycle Management - Start, stop, restart, status, logs, reconfigure, validate, cleanup all supported
Typical Use Cases
English Examples:
- "Help me deploy OpenHands to Huawei Cloud"
- "I want to install OpenHands on Flexus L instance"
- "Deploy OpenHands with Docker Compose on my existing server"
- "I want to configure OpenHands to use domestic China mirrors"
- "Help me deploy OpenHands with one click on a new Flexus L instance"
Workflow
This skill executes deployment in 7 phases. Each phase must complete before the next begins.
Phase 1: Environment Preparation
- Set environment variable:
PYTHONIOENCODING=utf-8 - Check dependency modules:
huaweicloudsdkcore,huaweicloudsdkcoc,huaweicloudsdkvpc,huaweicloudsdkecs,requests,pyyaml - Proceed directly to Phase 2 — credentials (HW_ACCESS_KEY, HW_SECRET_KEY) are assumed to be already configured in environment variables. Do NOT check, verify, or ask the user about credentials. If credentials are missing, scripts will error out automatically.
Phase 2: Create Flexus L Instance
⚠️ Requires customer confirmation before execution!
- If region not provided, interactively prompt user to select a region from supported options
- Display instance configuration to customer (name, flavor, region, estimated cost)
- Wait for customer confirmation (reply "confirm" or "yes")
- After confirmation: Call HCSS API (
POST /v1/light-instances) → Save order_id → Poll instance status untilACTIVE(2-5 minutes for COC registration) → Get instance_id, public_ip
Phase 3: COC Remote Dependency Installation
- Deliver and execute dependency installation script via COC on the target L instance
- Install/upgrade Docker Engine (if missing or version < 20.10) — apt-based installation only for Ubuntu 24.04; no
curl | shfallback (see Security Considerations SC2) - Install Docker Compose v2 plugin (if missing, tries multiple GitHub proxy sources with auto-fallback)
- Configure
/etc/docker/daemon.jsonwith 7 domestic Docker Hub mirrors + DNS settings + log rotation - Restart Docker daemon to apply changes
- Wait for completion (~8 minutes). Only retry if script execution errors occur.
Phase 4: COC Remote OpenHands Service Deployment
- Read deployment script (
openhands.sh) withOPENHANDS_RESOURCE_MODEenv var injected - Execute complete deployment script on instance via COC (must use background execution due to 10-30 min duration)
- Generate
docker-compose.yamlwith OpenHands app + sandbox configuration - Generate
.envwith resource limits, port mapping, and volume mounts - Start OpenHands via
docker compose up -d - Wait for completion (~15 minutes). Only retry if script execution errors occur.
Phase 5: Deep Deployment Verification
- Query COC deployment task status (poll every 30s until finished)
- Verify OpenHands container is running and healthy (
docker ps+docker inspect --format='{{.State.Health.Status}}') - Check port 8000 responds with HTTP 200 (
curl -s -o /dev/null -w "%{http_code}" http://localhost:8000) - Verify Web UI returns HTML content containing "openhands" (
curl -s http://localhost:8000 | grep -i "openhands") to avoid ISP proxy false positives - Check container logs are free of ERROR/Exception (
docker logs openhands 2>&1 | grep -iE "error|exception" | head -20) - Verify container restart count is 0 (
docker inspect --format='{{.RestartCount}}' openhands) - Security group port 8000 opening: In interactive mode, use
ask_userto ask user for confirmation and source CIDR before opening (does NOT default to 0.0.0.0/0). In non-interactive mode: if--remote-ipis provided, open with that CIDR; if not provided, skip security group opening entirely (do NOT call the security group API) and inform the user to open port 8000 manually. - Retrieve instance public IP via COC script execution (fallback chain:
ifconfig.me→ipinfo.io→hostname -I) - Output web access URL:
http://{public_ip}:8000 - Remind user to configure LLM API key in Web UI Settings
Do NOT report success based solely on
docker ps. Run all checks (1-6) in one pass and present comprehensive results to avoid user follow-up asking for deeper validation.
Phase 6: Model Configuration
- Access
http://<public-ip>:8000in browser - Configure LLM provider in Settings → LLM
- Enter API key in Web UI (stored securely, never in config files)
- API keys are NEVER stored in
.envfile — always configured via Web UI
Phase 7: Post-Deployment Configuration
- Resource mode selection:
OPENHANDS_RESOURCE_MODE=dedicated(90%) orshared(60% default) - Custom port: Set
OPENHANDS_PORTin.env(default 8000) - Custom version: Set
OPENHANDS_VERSION(default 1.35.0) - Mirror toggle: Set
DOMESTIC_MIRROR=falsefor overseas deployment - Timezone: Set
TZ(default Asia/Shanghai) - Service management: Use
bash scripts/openhands.shfor start/stop/restart/status/logs/reconfigure/validate/cleanup
COC Task Status Query
Query COC execution status by UUID. Supports single query, verbose output, wait-for-completion, and file loading. See references/verification-method.md for details.
| Status | Description |
|---|---|
| READY | Ready |
| PROCESSING | Running, waiting required |
| FINISHED | Completed successfully |
| ABNORMAL | Execution abnormal, failed |
| CANCELED | Canceled |
Deploy on an Existing Instance
If the Flexus L instance is already created, skip instance creation and deploy OpenHands directly onto it: run python scripts/caller.py deploy --deploy-mode existing-server → provide instance ID → select resource mode → COC deploys OpenHands. Keep the customer confirmation step before any COC execution.
# Deploy on existing instance (interactive)
python scripts/caller.py deploy --deploy-mode existing-server
# Deploy on existing instance (non-interactive, shared mode)
python scripts/caller.py deploy --deploy-mode existing-server \
--region cn-north-4 --resource-id instance-xxxx \
--resource-mode shared --non-interactive
# Independent COC deployment call
python scripts/caller.py deploy-openhands \
--region cn-north-4 --resource-id instance-xxxx \
--resource-mode dedicated
Resource Cleanup
Deployed Flexus L instances keep being billed (esp. prePaid / annual-monthly subscription). When no longer needed, release via Flexus L Console (Release/Delete, or Unsubscribe for prePaid) after customer confirmation. OpenHands data volumes under openhands-deploy/ directory should be backed up before cleanup.
OpenHands service cleanup (keeps data):
bash scripts/openhands.sh cleanup # Remove all containers but keep data volumes
Full cleanup (removes everything):
bash scripts/openhands.sh cleanup # Remove containers
# Then release the Flexus L instance via Huawei Cloud Console
Core Commands
Environment Setup
# Install Python SDK dependencies
python -m pip install huaweicloudsdkcore huaweicloudsdkcoc huaweicloudsdkvpc huaweicloudsdkecs requests pyyaml
Credentials: HW_ACCESS_KEY and HW_SECRET_KEY environment variables must be configured before deployment. Do NOT check, set, or prompt for credentials during deployment — they are assumed to be already present.
Deployment Commands
# 1. Deploy on new L instance (Path A, 90% dedicated)
python scripts/caller.py deploy --deploy-mode new-instance
# Non-interactive mode
python scripts/caller.py deploy --deploy-mode new-instance \
--name my-openhands --region cn-north-4 \
--plan-spec hf.medium.1.linux --period-type month --period-num 1 \
--deploy-openhands --non-interactive
# 2. Deploy on existing server (Path B, shared or dedicated)
python scripts/caller.py deploy --deploy-mode existing-server
# Non-interactive mode (shared, 60%)
python scripts/caller.py deploy --deploy-mode existing-server \
--region cn-north-4 --resource-id instance-xxxx \
--resource-mode shared --non-interactive
# 3. Independent COC deployment
python scripts/caller.py deploy-openhands \
--region cn-north-4 --resource-id instance-xxxx \
--resource-mode dedicated
# 4. List existing instances
python scripts/caller.py list --region cn-north-4
OpenHands Service Management Commands
# On the L instance via SSH — manage OpenHands directly
bash scripts/openhands.sh deploy # One-click deployment
bash scripts/openhands.sh install-docker # Docker setup only
bash scripts/openhands.sh status # Check status and resource usage
bash scripts/openhands.sh logs -f # View real-time logs
bash scripts/openhands.sh restart # Restart service
bash scripts/openhands.sh stop # Stop service
bash scripts/openhands.sh start # Start service
bash scripts/openhands.sh reconfigure # Re-detect resources after upgrade
bash scripts/openhands.sh validate # Validate docker-compose.yaml syntax
bash scripts/openhands.sh cleanup # Clean up (remove containers, keep data)
Custom Port and Version
# Deploy on custom port with specific OpenHands version
OPENHANDS_PORT=8001 OPENHANDS_VERSION=1.35.0 bash scripts/openhands.sh deploy
# Use official Docker Hub image source instead of domestic mirror
DOMESTIC_MIRROR=false bash scripts/openhands.sh deploy
# Override resource mode
OPENHANDS_RESOURCE_MODE=dedicated bash scripts/openhands.sh deploy # 90%
OPENHANDS_RESOURCE_MODE=shared bash scripts/openhands.sh deploy # 60% (default)
Parameter Confirmation & User-Configurable Parameters
See references/parameters-and-output.md for the full parameter confirmation template, user-configurable parameters (caller.py, openhands.sh, docker-compose.yaml), and directory structure.
Web UI Access
Web UI access requires two conditions:
- OpenHands service running and bound to port 8000 (auto-configured by deployment script)
- Security group allows port 8000 (opened by
sg_rule.pyafter user confirmation and CIDR input — does NOT default to 0.0.0.0/0)
.env Configuration (Service-side)
The .env file at openhands-deploy/.env on the target instance contains auto-generated configuration:
| .env Variable | Purpose | Default Value |
|---|---|---|
OPENHANDS_PORT |
Web UI access port | 8000 |
OPENHANDS_RESOURCE_MODE |
Resource allocation mode | shared |
TZ |
Timezone setting | Asia/Shanghai |
Important: When updating config items in
.env, first usesedto delete the old line, then useechoto append the new line, to avoid variable accumulation during repeated deployments. Correct approach:sed -i '/^OPENHANDS_IMAGE=/d' .env && echo "OPENHANDS_IMAGE=xxx" >> .env
Security: LLM API keys are NEVER stored in
.env. Always configure via OpenHands Web UI Settings.
Security Group Configuration (Cloud-side)
- After deployment, the skill asks the user to confirm opening port 8000 and provide a source CIDR
- The skill opens inbound port 8000 (TCP) via VPC API with the user-specified CIDR (does NOT default to 0.0.0.0/0)
- Alternatively, login to Flexus L Console
- Find your OpenHands instance → instance details → Security/Network
- Configure security group rules to open port 8000 (TCP inbound) with your desired CIDR
Access URL: http://<instance_public_ip>:8000
Security Warning: After opening the port, OpenHands Web interface will be accessible. For production, place behind a reverse proxy with authentication. Docker socket access is restricted via docker-socket-proxy — the OpenHands container connects through a proxy that whitelists only containers/exec/images API endpoints, preventing host-root-equivalent access.
Huawei Cloud Credential Configuration
Credential priority: environment variables (primary method for this skill).
Critical: The agent MUST NOT check, detect, or ask for AK/SK/Token at any point. The following documentation is for the user to configure their environment before invoking the skill — the agent never executes these commands.
Option 1: Environment Variables (Recommended)
Credentials are passed via environment variables. Set them before running caller.py:
# Permanent credentials
export HW_ACCESS_KEY=<your-access-key>
export HW_SECRET_KEY=<your-secret-key>
# Temporary credentials (STS Token)
export HW_ACCESS_KEY=<your-access-key>
export HW_SECRET_KEY=<your-secret-key>
export HW_SECURITY_TOKEN=<your-security-token>
| Environment Variable | Description | Required |
|---|---|---|
HW_ACCESS_KEY |
Access Key (permanent or temporary) | Yes |
HW_SECRET_KEY |
Secret Key (permanent or temporary) | Yes |
HW_SECURITY_TOKEN |
Security Token (STS only; required for security group operations with STS) | No |
Option 2: OpenHands API Key Configuration (Post-Deployment)
LLM provider API keys are configured separately from Huawei Cloud credentials:
| Method | Description |
|---|---|
| Web UI Settings | Configure in Settings → LLM within OpenHands interface (stored securely, never in config files) |
API keys are NEVER stored in
.envfile. Always configure via Web UI Settings.
Key API Endpoints & Output Standards
See references/parameters-and-output.md for the full API endpoints table, Docker mirror sources, success/error output templates, and error handling rule.
References
The following reference documents provide detailed information for this skill:
| Document | Description |
|---|---|
| references/iam-policies.md | IAM permission policies and policy JSON for deployment |
| references/verification-method.md | Verification methods and COC task status query procedures |
| Flexus L Instance Purchase Guide | Purchasing a Flexus L Instance |
| HCSS API Reference | HCSS API for Flexus L management |
| Huawei Cloud COC | Cloud Operations Center |
| OpenHands Official | OpenHands GitHub Repository |
| OpenHands Docs | OpenHands Documentation |
| OpenHands Docker Image | ghcr.io/openhands/agent-canvas |
| Docker Compose Reference | Docker Compose Documentation |
| DaoCloud Mirror | DaoCloud Image Mirror |
Troubleshooting & Security Details
See references/troubleshooting-and-security.md for the full troubleshooting table, security considerations (SC2, PE4, DES002, SG1), API parameter notes, and platform compatibility guide.
