qwen-code

Official

Qwen Code Agent runtime — Dashscope-powered AI autonomous deployment agent

Install

abx
abx template deploy ./qwen-code -y --alias qwen-code
abx create --template qwen-code
# TemplateID from `abx --json template deploy` is also accepted

On each provider

Express publishes this directory with abx template deploy. The other providers do not declare templates.build, so they do not register this directory.

ProviderStatusHow
Alibaba Cloud Agent Sandbox Express EditionDeploys on ExpressUse →
Alibaba Cloud Agent Sandbox Container EditionExisting template idUse →
CubeSandboxExisting template idUse →
E2BExisting template idUse →
OpenSandboxImage URI, not this directoryUse →

About

中文版 | English


English

Sandbox runtime for the Qwen coding agent — supports qwen-code-driven autonomous deployment and provides a Python 3.12 + Node.js 22 AI coding foundation.

Environment

This template comes preinstalled with the following tools and dependencies:

Category Details
Base image python:3.12-slim
Python Python 3.12 + venv (at /opt/venv)
Node.js Node.js 22.x + npm
Python packages dashscope, openai>=1.0, httpx, rich
Node.js packages @qwen-code/qwen-code@0.23.0
System tools git, curl, wget, ripgrep, jq, build-essential
Resources 2 CPU / 4096 MB memory

Installation

Install from a local path:

abx template install ./qwen-code --registry-type local

Install from GitHub:

abx template install alibaba-agent-sandbox/awesome-templates//qwen-code

Usage

Create a sandbox instance and pass in the API key:

abx create --template qwen-code --env DASHSCOPE_API_KEY=sk-xxx

Call a Qwen model inside the sandbox via the DashScope SDK:

abx exec <sandbox-id> -- python3 -c "
import dashscope
from dashscope import Generation
response = Generation.call(model='qwen-turbo', prompt='Write a quicksort algorithm')
print(response.output.text)
"

The OpenAI-compatible interface is also supported:

abx exec <sandbox-id> -- python3 -c "
from openai import OpenAI
client = OpenAI(
    api_key='your-dashscope-key',
    base_url='https://dashscope.aliyuncs.com/compatible-mode/v1'
)
response = client.chat.completions.create(
    model='qwen-turbo',
    messages=[{'role': 'user', 'content': 'Write a quicksort'}]
)
print(response.choices[0].message.content)
"

Using the Python SDK:

from agent_sandbox import Sandbox

sandbox = Sandbox.create_sync(
    template="qwen-code",
    env={"DASHSCOPE_API_KEY": "sk-xxx"}
)

result = sandbox.commands.run("python3 --version && node --version")
print(result.stdout)

Configuration

Environment Variables

Variable Description Required
DASHSCOPE_API_KEY Alibaba Cloud DashScope API key Yes
WORKSPACE Working directory path, defaults to /workspace No

Manual AI Coding Tool Installation

This template already ships with the qwen-code CLI, ready to use:

# Use qwen-code for NL-based deployment
abx run <sandbox-id> qwen --prompt "Deploy this FastAPI project"

# Or use the qwen command directly inside the sandbox
abx exec <sandbox-id> -- qwen -p "Analyze the project and deploy it" --yolo

To install additional tools:

# Install extra Python packages
abx exec <sandbox-id> -- pip install <agent-package>

# Install extra Node.js tools
abx exec <sandbox-id> -- npm install -g <agent-tool>

Notes

  • API key security: Never hardcode DASHSCOPE_API_KEY into the template; always inject it via the --env option or environment variables.
  • Network access: The DashScope API (dashscope.aliyuncs.com) must be reachable — make sure the sandbox has outbound internet connectivity.
  • Compatible interface: DashScope offers an OpenAI-compatible mode, so Qwen models can be called directly through the openai library.
  • Virtual environment: Python packages are installed in /opt/venv; no manual activation is needed since PATH is preconfigured.

中文

通义千问(Qwen)编码 Agent 的沙箱运行环境,支持 qwen-code 驱动的 AI 自主部署,提供 Python 3.12 + Node.js 22 的 AI 编程基础环境。

环境说明

本模板预装以下工具和依赖:

类别 内容
基础镜像 python:3.12-slim
Python Python 3.12 + venv 虚拟环境(位于 /opt/venv)
Node.js Node.js 22.x + npm
Python 包 dashscope、openai>=1.0、httpx、rich
Node.js 包 @qwen-code/qwen-code@0.23.0
系统工具 git、curl、wget、ripgrep、jq、build-essential
资源配置 2 CPU / 4096 MB 内存

安装方式

从本地安装:

abx template install ./qwen-code --registry-type local

从 GitHub 安装:

abx template install alibaba-agent-sandbox/awesome-templates//qwen-code

使用示例

创建沙箱实例并传入 API Key:

abx create --template qwen-code --env DASHSCOPE_API_KEY=sk-xxx

在沙箱中通过 DashScope SDK 调用 Qwen 模型:

abx exec <sandbox-id> -- python3 -c "
import dashscope
from dashscope import Generation
response = Generation.call(model='qwen-turbo', prompt='编写一个快速排序算法')
print(response.output.text)
"

也支持使用 OpenAI 兼容接口:

abx exec <sandbox-id> -- python3 -c "
from openai import OpenAI
client = OpenAI(
    api_key='your-dashscope-key',
    base_url='https://dashscope.aliyuncs.com/compatible-mode/v1'
)
response = client.chat.completions.create(
    model='qwen-turbo',
    messages=[{'role': 'user', 'content': '编写一个快速排序'}]
)
print(response.choices[0].message.content)
"

使用 Python SDK:

from agent_sandbox import Sandbox

sandbox = Sandbox.create_sync(
    template="qwen-code",
    env={"DASHSCOPE_API_KEY": "sk-xxx"}
)

result = sandbox.commands.run("python3 --version && node --version")
print(result.stdout)

配置说明

环境变量

变量名 说明 必填
DASHSCOPE_API_KEY 阿里云 DashScope API 密钥 是
WORKSPACE 工作目录路径,默认 /workspace 否

手动安装 AI 编码工具

本模板已预装 qwen-code CLI 工具,可直接使用:

# 使用 qwen-code 进行 NL 部署
abx run <sandbox-id> qwen --prompt "部署这个 FastAPI 项目"

# 或在沙箱内直接使用 qwen 命令
abx exec <sandbox-id> -- qwen -p "分析项目并部署" --yolo

如需安装额外工具:

# 安装额外 Python 包
abx exec <sandbox-id> -- pip install <agent-package>

# 安装额外 Node.js 工具
abx exec <sandbox-id> -- npm install -g <agent-tool>

注意事项

  • API Key 安全:请勿将 DASHSCOPE_API_KEY 硬编码到模板中,始终通过 --env 参数或环境变量注入。
  • 网络访问:需要访问 DashScope API(dashscope.aliyuncs.com),确保沙箱具备外网连接能力。
  • 兼容接口:DashScope 提供 OpenAI 兼容模式,可通过 openai 库直接调用 Qwen 模型。
  • 虚拟环境:Python 包安装在 /opt/venv 中,使用时无需手动激活,PATH 已自动配置。

Deploy and local e2e

Install and register this template:

abx template install alibaba-agent-sandbox/awesome-templates//qwen-code

From this directory (build, push, and register):

abx deploy

From the repository root, with agent-sandbox-server and httpx installed:

python3 scripts/run_local_e2e.py

That starts python3 commands.py in this directory and runs e2e_test.py.

Files