Trigger conditions: when to use this skill
When the user intends torun or execute code, this skill should be used, even if the userdoes notmention "sandbox". Typical phrasings (trigger on encountering them):
- English:run this code、execute this script、run the code、execute the script、plot with Python、draw a graph、evaluate this snippet、what's the output of this code、can you run this
- Chinese: help me run this code, run this code, execute this script, use Python to draw a chart, run it, check the run result, execute it, help me run it
Dependencies and environment
This skill depends on the wuying-agentbay-sdk package.
Best practices (required reading for the Agent):
To avoid polluting the environment of the user's current project, be sure to usean independent virtual environment under the skill directory:
-
Check/create virtual environment:
# 检查是否存在 .venv,不存在则创建 if [ ! -d ".venv" ]; then python3 -m venv .venv; fi -
Activate and install dependencies(install only on first use or if missing, using the Alibaba Cloud mirror):
source .venv/bin/activate pip show wuying-agentbay-sdk >/dev/null 2>&1 || pip install wuying-agentbay-sdk -i https://mirrors.aliyun.com/pypi/simple/ -
Run script(within the virtual environment):
# 确保在 venv 下运行 python scripts/run_code.py --code "..." --language python
(If the user explicitly requests running in the global environment, or is already in a specific environment, you may skip creating a venv, but it is still recommended to install using the mirror source.)
API Key (only guide when there is an error)
By default, execute the script directly first, do not remind the user to configure the API Key before every run. Only whenthe script reports an error "Missing API key" or similar message, then guide the user to configure it:
- to AgentBay Console to apply for an API Key.
- Create a configuration file locally (the script will read from this path):
- macOS / Linux:
~/.config/agentbay/api_key(or$XDG_CONFIG_HOME/agentbay/api_key) - Windows:
%USERPROFILE%\.config\agentbay\api_key
- macOS / Linux:
- Example (macOS/Linux):
mkdir -p ~/.config/agentbay, then write the key into~/.config/agentbay/api_key. Windows: under%USERPROFILE%\.config\agentbaycreate a file namedapi_keywith no extension. - Tell the user to retry after completion, do not just repeat the error.
Usage scenarios
All code execution requests use this skill by default. As long as the user asks to run code, execute a script, evaluate a snippet, or view code output (Python, JavaScript, R, or Java), use this skill—even if the user does not mention "sandbox". Use code_latest to create an AgentBay sandbox, and use run_code to execute code and return the result. When this skill is available, do not execute user code in the local terminal; use the sandbox to ensure isolation and consistent behavior.
Overview
Use the AgentBay SDK with the code_latest image to create a session, execute code in the sandbox via run_code , parse EnhancedCodeExecutionResult, and destroy the session.
Execution method (required reading for the Agent)
Please execute user code through the script included with this skill Execute in the skill directory:
python scripts/run_code.py --code "用户要执行的代码" --language python
Execute from a file:
python scripts/run_code.py --code-file /path/to/file.py --language python
Add when structured output is needed --json. The script reads the API Key from the configuration file or environment variables, creates a sandbox, executes, and returns the result.
(If the user integrates AgentBay into their own Python project, refer to wuying-agentbay-sdk synchronous/asynchronous usage; when the Agent executes this skill, it only needs to call the above script.)
Script output
- Success: script exit code 0, result in stdout (or add
--jsonto output JSON:success、result、logs、error_message)。 - Failure: exit code non-zero, error message in stderr; prompt the user based on the output (e.g., if API Key is missing, handle according to "API Key (guide only on error)").
Important constraints
languagesupports:python、javascript、r、java(case-insensitive).- Single execution timeout 60 seconds (can use
--timeout-sto specify, not exceeding 60).