lybic cloud-computer skill

TotalClaw 作者 totalclaw

Lybic Sandbox 是一个专为代理和自动化工作流程而构建的云沙箱。将其视为可按需启动的一次性云计算机。代理可以执行 GUI 操作,例如查看屏幕、单击、键入和处理弹出窗口,这使其非常适合 API 缺失或不完整的遗留应用程序和复杂流程。它是为控制和可观察性而设计的。您可以实时监控执行情况,在需要时停止它,并使用日志和重播来调试、重现运行和评估可靠性。对于长时间运行的任务、迭代实验或敏感环境,沙盒执行有助于降低风险和运营开销。

安装 / 下载方式

TotalClaw CLI推荐
totalclaw skills install shop:totalclaw:totalclaw~aenjoy-lybic-sandbox
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~aenjoy-lybic-sandbox/file -o aenjoy-lybic-sandbox.md
## 概述(中文)

Lybic Sandbox 是一个专为代理和自动化工作流程而构建的云沙箱。将其视为可按需启动的一次性云计算机。代理可以执行 GUI 操作,例如查看屏幕、单击、键入和处理弹出窗口,这使其非常适合 API 缺失或不完整的遗留应用程序和复杂流程。它是为控制和可观察性而设计的。您可以实时监控执行情况,在需要时停止它,并使用日志和重播来调试、重现运行和评估可靠性。对于长时间运行的任务、迭代实验或敏感环境,沙盒执行有助于降低风险和运营开销。

## 原文

# Lybic Sandbox Control Skill

You are an expert at controlling Lybic cloud sandboxes using the Lybic Python SDK.

## Your Capabilities

You can help users interact with Lybic cloud sandboxes to:

1. **Manage Sandboxes**
   - Create sandboxes (Windows/Linux/Android)
   - List, get details, and delete sandboxes
   - Monitor sandbox state and lifecycle

2. **Perform GUI Automation**
   - **Desktop (Windows/Linux)**: Mouse clicks, keyboard input, scrolling, dragging
   - **Mobile (Android)**: Touch, swipe, long press, app management
   - Take screenshots for visual feedback

3. **Execute Code and Commands**
   - Run Python, Node.js, Go, Rust, Java code
   - Execute shell commands and scripts
   - Handle stdin/stdout/stderr with base64 encoding

4. **Manage Files**
   - Download files from URLs into sandbox
   - Copy files within sandbox or between locations
   - Read and write files in sandbox

5. **Network Operations**
   - Create HTTP port mappings
   - Forward sandbox ports to public URLs
   - Enable external access to sandbox services

6. **Project Management**
   - Create and organize projects
   - Manage sandboxes within projects
   - Track organization usage

## Prerequisites

The Lybic Python SDK must be installed:
```bash
pip install lybic
```

Users need Lybic credentials set via environment variables:
- `LYBIC_ORG_ID` - Organization ID
- `LYBIC_API_KEY` - API key

Of course, these two parameters can also be manually specified and passed to the client.

```python
import asyncio
from lybic import LybicClient, LybicAuth

async def main():
    async with LybicClient(LybicAuth(
            org_id="your_org_id", # Lybic organization ID
            api_key="your_api_key"
         )) as client:
        # Your code here
        pass
```

## Code Guidelines

### 1. Always use async/await pattern

```python
import asyncio
from lybic import LybicClient

async def main():
    async with LybicClient() as client:
        # Your code here
        pass

if __name__ == '__main__':
    asyncio.run(main())
```

### 2. Use proper error handling

```python
try:
    result = await client.sandbox.create(name="test", shape="beijing-2c-4g-cpu-linux")
    print(f"Created: {result.id}")
except Exception as e:
    print(f"Error: {e}")
```

### 3. Handle base64 encoding for process I/O

```python
import base64

# For stdin
code = "print('hello')"
stdin_b64 = base64.b64encode(code.encode()).decode()

# For stdout/stderr
result = await client.sandbox.execute_process(...)
output = base64.b64decode(result.stdoutBase64 or '').decode()
```

### 4. Use fractional coordinates for GUI actions

```python
# Recommended: Resolution-independent
action = {
    "type": "mouse:click",
    "x": {"type": "/", "numerator": 1, "denominator": 2},  # 50%
    "y": {"type": "/", "numerator": 1, "denominator": 2},  # 50%
    "button": 1
}

# Alternative: Absolute pixels (less portable)
action = {
    "type": "mouse:click",
    "x": {"type": "px", "value": 500},
    "y": {"type": "px", "value": 300},
    "button": 1
}
```

## Common Patterns

### Pattern 1: Create sandbox and run code

```python
import asyncio
import base64
from lybic import LybicClient

async def run_code_in_sandbox():
    async with LybicClient() as client:
        # Create linux based code sandbox
        sandbox = await client.sandbox.create(
            name="code-runner",
            shape="beijing-2c-4g-cpu-linux"
        )
        
        # Execute code
        code = "print('Hello from sandbox')"
        result = await client.sandbox.execute_process(
            sandbox.id,
            executable="python3",
            stdinBase64=base64.b64encode(code.encode()).decode()
        )
        
        print(base64.b64decode(result.stdoutBase64).decode())
        
        # Cleanup
        await client.sandbox.delete(sandbox.id)

asyncio.run(run_code_in_sandbox())
```

### Pattern 2: GUI automation with screenshot

```python
import asyncio
from lybic import LybicClient

async def automate_gui():
    async with LybicClient() as client:
        sandbox_id = "SBX-xxxx"
        
        # Take initial screenshot
        url, img, _ = await client.sandbox.get_screenshot(sandbox_id)
        img.show()
        
        # Click at center
        await client.sandbox.execute_sandbox_action(
            sandbox_id,
            action={
                "type": "mouse:click",
                "x": {"type": "/", "numerator": 1, "denominator": 2},
                "y": {"type": "/", "numerator": 1, "denominator": 2},
                "button": 1
            }
        )
        
        # Type text
        await client.sandbox.execute_sandbox_action(
            sandbox_id,
            action={
                "type": "keyboard:type",
                "content": "Hello!"
            }
        )
        
        # Press Enter
        await client.sandbox.execute_sandbox_action(
            sandbox_id,
            action={
                "type": "keyboard:hotkey",
                "keys": "Return"
            }
        )

asyncio.run(automate_gui())
```

### Pattern 3: Download file and process

```python
import asyncio
import base64
from lybic import LybicClient
from lybic.dto import FileCopyItem, HttpGetLocation, SandboxFileLocation

async def download_and_process():
    async with LybicClient() as client:
        sandbox_id = "SBX-xxxx"
        
        # Download file
        await client.sandbox.copy_files(
            sandbox_id,
            files=[
                FileCopyItem(
                    id="dataset",
                    src=HttpGetLocation(url="https://example.com/data.csv"),
                    dest=SandboxFileLocation(path="/tmp/data.csv")
                )
            ]
        )
        
        # Process with Python
        code = """
import pandas as pd
df = pd.read_csv('/tmp/data.csv')
print(df.describe())
"""
        result = await client.sandbox.execute_process(
            sandbox_id,
            executable="python3",
            stdinBase64=base64.b64encode(code.encode()).decode()
        )
        
        print(base64.b64decode(result.stdoutBase64).decode())

asyncio.run(download_and_process())
```

## Action Reference

### Mouse Actions (Computer Use)

```python
# Click
{"type": "mouse:click", "x": {...}, "y": {...}, "button": 1}  # 1=left, 2=right

# Double-click
{"type": "mouse:doubleClick", "x": {...}, "y": {...}, "button": 1}

# Move
{"type": "mouse:move", "x": {...}, "y": {...}}

# Drag
{"type": "mouse:drag", "startX": {...}, "startY": {...}, "endX": {...}, "endY": {...}}

# Scroll
{"type": "mouse:scroll", "x": {...}, "y": {...}, "stepVertical": -5, "stepHorizontal": 0}
```

### Keyboard Actions (Computer Use)

```python
# Type text
{"type": "keyboard:type", "content": "Hello, World!"}

# Hotkey
{"type": "keyboard:hotkey", "keys": "ctrl+c"}  # Copy
{"type": "keyboard:hotkey", "keys": "Return"}  # Enter
{"type": "keyboard:hotkey", "keys": "ctrl+shift+s"}  # Save as
```

### Touch Actions (Mobile Use)

```python
# Tap
{"type": "touch:tap", "x": {...}, "y": {...}}

# Long press
{"type": "touch:longPress", "x": {...}, "y": {...}, "duration": 2000}

# Swipe
{"type": "touch:swipe", "x": {...}, "y": {...}, "direction": "up", "distance": {...}}

# Android buttons
{"type": "android:back"}
{"type": "android:home"}
```

### App Management (Mobile Use)

```python
# Start app
{"type": "os:startApp", "packageName": "com.android.chrome"}
{"type": "os:startAppByName", "name": "Chrome"}

# Close app
{"type": "os:closeApp", "packageName": "com.android.chrome"}
{"type": "os:closeAppByName", "name": "Chrome"}

# List apps
{"type": "os:listApps"}
```

### Common Actions

```python
# Screenshot
{"type": "screenshot"}

# Wait
{"type": "wait", "duration": 3000}  # milliseconds

# Task status
{"type":