# Use Agent Skill to manage sandbox

`ucloud-sandbox` skill allows AI Agents that support skills such as Codex, Claude Code, and Gemini CLI to understand UCloud Sandbox CLI. Once installed, you can let the Agent create and manage sandboxes, execute commands, transfer files, and manage snapshots and templates directly using natural language without having to memorize the full set of CLI parameters.

Common operations supported by this skill include:

- Install and configure `ucloud-sandbox-cli`
- Create, query, connect, pause and terminate sandboxes
- Execute commands in the sandbox and view port access addresses and resource indicators
- Browse sandbox files and upload or download files between local and sandbox
- Create and manage snapshots, builds and management templates

> Skill will guide Agent to call UCloud Sandbox CLI, but will not replace UCloud Sandbox account and API Key. Certification still needs to be completed before actual sandbox operations can be performed.

## Preparation

Before you begin, make sure your machine has:

- Node.js and `npx` for skill installation
- An AI Agent that supports skills, such as Codex, Claude Code or Gemini CLI

## Install skill

Enter the project directory where the skill needs to be used and execute:

```bash
npx skills add ucloud/ucloud-sandbox-cli -s ucloud-sandbox
```

Select the Agent to be installed according to the command line prompts. After the installation is complete, restart the Agent or create a new session to load the `ucloud-sandbox` skill.

The source files and latest instructions of Skill can be viewed in [ucloud-sandbox-cli GitHub repository](https://github.com/ucloud/ucloud-sandbox-cli/tree/main/skills/ucloud-sandbox).

## Configure authentication

For first time use, perform an interactive login in a real terminal:

```bash
ucloud-sandbox-cli login
```

API Key can be obtained from [Star Map Platform Key Management] (https://astraflow.ucloud.cn/modelverse/api-keys). You can also follow the instructions in [Prerequisites and Authentication](/docs/agent-sandbox/product/prerequisites.md) to configure the API Key and region through environment variables.

> Do not write API Key into prompts, code repositories or chat history. The login command requires reading interactive input. Please complete it in your own terminal. Do not let the Agent enter or save the API Key on your behalf.

## Prompt word example

After the installation is complete, you can describe the target directly to the Agent. The prompt words below can replace the sandbox ID, file path, port, and template name as needed.

### Check environment

```text
Check whether the latest version of ucloud-sandbox-cli is installed on this machine and confirm the currently configured region. Do not output API Key.
```

If the CLI has not been installed, the Agent will complete the installation according to the instructions in the skill or give installation steps suitable for the current system.

### Create a sandbox and execute commands

```text
Use the base template to create a sandbox with a timeout of 1 hour, execute python --version in it, and then tell me the sandbox ID and execution results.
```

You can also let the Agent complete a set of operations within an existing sandbox:

```text
Connect to the sandbox <sandbox-id>, view the /home/user directory, and output the current working directory and disk usage in the sandbox.
```

### Upload and download files

```text
Upload the local ./app.py to /home/user/app/app.py of the sandbox <sandbox-id>, and then run it in the sandbox.
```

```text
Download /home/user/app/output.csv in sandbox <sandbox-id> to local ./downloads/output.csv.
```

### Access services in the sandbox

```text
Start this Web project in the sandbox <sandbox-id>, listen on 0.0.0.0:3000, and tell me the external access address after confirming that the service is normal.
```

### Check running status

```text
List all currently running sandboxes and view CPU and memory metrics for sandbox <sandbox-id> for the last hour.
```

### Use snapshot reuse environment

```text
Create a snapshot for sandbox <sandbox-id>. After the creation is successful, use this snapshot to start a new sandbox and tell me the new sandbox ID.
```

### Build custom templates

```text
Help me initialize a template called python-data-env, using 2-core CPU and 2048 MB memory, with pandas and requests pre-installed. Show me the build configuration first and confirm before starting the build.
```

### Pause or terminate the sandbox

```text
Pause sandbox <sandbox-id> and confirm its latest status when finished.
```

Terminating the sandbox and deleting files, snapshots, or templates are destructive operations. It is recommended to ask the Agent to check the target first in the prompt word:

```text
I want to terminate sandbox <sandbox-id>. Please show its basic information first and wait for my confirmation. Do not terminate immediately.
```

## Usage suggestions

- Try to give a clear sandbox ID, remote path, port and expected result in the prompt word.
- Let the Agent verify the results after the operation is completed, such as checking whether a process, service address, or file exists.
- When reading `.env`, configuration files and other files that may contain credentials, explicitly request not to echo sensitive information.
- Before performing operations such as terminating the sandbox, deleting files, deleting snapshots, or deleting templates, check the target and confirm the scope of impact.
