SWE-Gym + Claude Code 快速开始
July 25, 2026 · View on GitHub
本文说明如何使用公开版 Dressage 准备 SWE-Gym 数据,在 E2B task template 中运行 Claude Code,对每个 patch 使用全新沙箱评测,并启动 Qwen3.5-4B 同步 GRPO recipe。
1. 安装仓库和数据依赖
git submodule update --init --recursive
python3 -m pip install -e .
python3 -m pip install --no-build-isolation blackbox_server/
python3 -m pip install pyarrow huggingface_hub
python3 -m pip install \
'swegym @ git+https://github.com/SWE-Gym/SWE-Bench-Package.git@16dd480cce9b27bf111a362d280881c6def5d2a7'
固定版本的 SWE-Gym package 只在数据准备阶段使用。转换器会把官方的
repository-specific 测试脚本和 log parser 写入生成数据,因此 task sandbox
不需要安装 swegym Python package。
2. 准备 E2B template
每条 SWE-Gym 数据需要一个全新的 task image,并满足:
- 仓库及原始测试环境位于
/testbed; - 已安装 Claude Code;
- 已安装当前公开仓库的 Blackbox Server;
- Blackbox Server 监听
31000端口。
先从公开 Blackbox Server 构建 wheel,并打包独立运行时:
python3 -m pip install build uv
python3 -m build --wheel --outdir dist blackbox_server/
export CLAUDE_CODE_BBS_VERSION=1.1.0
export CLAUDE_CODE_BBS_WHEEL_URL="$PWD/dist/dressage_blackbox_server-1.1.0-py3-none-any.whl"
export CLAUDE_CODE_ARTIFACT_DIR="$PWD/data/claude-code-artifacts"
bash dressage/recipes/swegym/prepare_claude_code_sandbox_artifacts.sh
为每个不同的 SWE-Gym task image 构建一个 E2B template,并准备从原始 Docker image 到 E2B template name 的 JSON 映射:
{
"xingyaoww/sweb.eval.x86_64.example:latest": "e2b-swegym-example"
}
使用仓库工具枚举 image、逐个构建 template,并完成 smoke test:
python3 examples/data/swegym/prepare_swegym_e2b.py list-images \
--download \
--download-dir data/swegym-source \
--split train \
--output data/swegym-images.txt
export E2B_API_KEY=e2b_...
export TASK_IMAGE=xingyaoww/sweb.eval.x86_64.example:latest
export TEMPLATE_NAME=e2b-swegym-example
python3 examples/data/swegym/prepare_swegym_e2b.py build
python3 examples/data/swegym/prepare_swegym_e2b.py smoke
对 data/swegym-images.txt 中的每个 image 重复 build,为其分配唯一
template name,并记录最终映射。更多说明见
完整实验说明。
3. 转换 SWE-Gym 数据
转换已下载的 293 条训练数据:
python3 examples/data/swegym/prepare_swegym_data.py \
data/swegym-train-claude-code-e2b.jsonl \
--input data/swegym-source/train.parquet \
--split train \
--provider e2b \
--sandbox-image-map data/e2b-template-map.json \
--blackbox-type claude_code \
--max-turns 80 \
--permission-mode acceptEdits
单条转换 smoke 可追加 --limit 1;转换器会先校验完整 split,再应用
limit。最终 JSONL 不含 gold patch,并包含:
- 强制执行的 before-agent Git sanitizer;
- 固定版本的官方 SWE-Gym evaluator 和 log parser;
- task-specific
FAIL_TO_PASS与PASS_TO_PASS; - Claude Code backend options,包括
working_directory=/testbed; - 每条任务对应的 E2B template。
4. Smoke-test template
占用训练 GPU 前,先确认 template 能恢复 Blackbox Server 并暴露 31000:
python3 examples/data/swegym/prepare_swegym_e2b.py smoke \
--template-name e2b-swegym-example
还应至少完整验证一条真实任务:Claude Code 能在 /testbed 生成 patch,
全新 evaluation sandbox 能输出 DRESSAGE_SWEGYM_REWARD_JSON= marker。
5. 启动同步 GRPO
在同一模型目录准备 Qwen3.5-4B Hugging Face 和 Megatron distributed checkpoint,然后执行:
export MODEL_ROOT=/path/to/models
export PROMPT_DATA="$PWD/data/swegym-train-claude-code-e2b.jsonl"
export DRESSAGE_SANDBOX_PROVIDER=e2b
export DRESSAGE_E2B_API_KEY=e2b_...
export DRESSAGE_E2B_BLACKBOX_PORT=31000
export DRESSAGE_PROXY_URL=https://proxy.example.com
bash examples/scripts/run_dressage_swegym_qwen3.5_4b_claude_code_sync_4_node.sh
DRESSAGE_PROXY_URL 必须是 E2B 沙箱能够访问的 HTTP(S) 地址。
launcher 会显式选择 `dressage.rollout.generate.blackbox_dispatch_swegym.generate$。通用 \text{blackbox} \text{dispatch} 不包含 \text{SWE}-\text{Gym} 判断;\text{fresh} \text{evaluation} 和 \text{trajectory} \text{integrity} 检查都由专用 \text{dispatch} 负责。
参考默认值保留已评审实验配置:\text{TP2}/\text{CP4}、8 \text{prompts} \times 16 \text{samples}、\text{global} \text{batch} \text{size} 128、500 次 \text{rollout} \text{update}、\text{normalized} \text{GRPO} \text{advantage}、\text{vanilla} \text{token}-\text{level} \text{TIS},以及系数为 $0.001` 的 low-variance KL loss。基础设施和 拓扑可通过环境变量覆盖。