Coding Agent Distillation

Updated at:

The Coding Agent Distillation template uses a coding agent to modify real code in a remote sandbox, then replays the changes to run tests for validation. It produces multi-turn SFT datasets in ShareGPT format. These datasets are suitable for training small models to locate issues, modify code, and verify results in real-world code repositories.

Template overview

Use the Coding Agent Distillation template to train models with coding capabilities. A coding agent modifies real code in a remote sandbox, and the changes are then replayed and tested in a clean sandbox. Only trajectories whose changes actually make the tests pass are kept, producing multi-turn SFT datasets in ShareGPT format. Unlike agent distillation that simulates tool calls, every step in this data pipeline includes actual execution and anti-cheating checks. These datasets are suitable for training small models to locate issues, modify code, and verify results in real-world code repositories.

Important

This template supports one-stage creation only: Distillation Data Build. It does not include a student model training stage.

The Coding Agent Distillation template pipeline includes the following steps:

Step

Name

Description

1

Sandbox execution

Creates an independent remote sandbox for each seed and extracts its workspace. The coding agent then modifies the code as described in the task, and the complete interaction trajectory is recorded.

2

Replay and test validation

Replays the file changes from the trajectory in a clean sandbox and runs the validation command specified by the seed. It also runs anti-cheating checks, such as whether test files were modified, whether all test cases were skipped, or whether environment errors were counted as passes. Outputs a score and a conclusion.

3

Build the SFT dataset

Organizes the trajectories that pass validation into multi-turn conversation training samples in ShareGPT format.

Procedure

  1. Log on to the PAI console. In the left-side navigation pane, choose Model Application > Model Distillation (ModelDistill).

  2. Click Create task to open the Distillation Template tab, or open the Distillation Template tab directly.

  3. Select Coding Agent Distillation and click Use Template to open the Create Distillation Task page. Configure the following key parameters and keep the default values for the others.

  4. In Basic Configuration, set the following parameters:

    • Task name: The system automatically populates this field.

    • Output Path: Specify an OSS path that you have permission to access, such as oss://mybucket.oss-cn-hangzhou-internal.aliyuncs.com/coding-agent-distill/.

      Note

      Create a separate output directory for each distillation task to prevent files from being overwritten. The OSS bucket must be in the same region as the PAI service.

  5. Click Next to open Build distillation data:

    • Teacher model: Set the source to Token Service and select a teacher model (such as qwen3.8-max). Do not select a judge model; the teacher model is reused as the judge model.

    • Dataset: Select an OSS directory that you have permission to access. You must select the entire directory, not only a JSONL file. You can download and use the sample directly.

    • Distillation Configuration: A default configuration is provided and can be modified as needed. Pay attention to the following parameters:

      • coding_agent.harness.max_turns: The maximum number of interaction turns for a single seed. The default value is 150. Configure this parameter together with timeout, because the agent modifies code and runs tests in the sandbox during each turn.

      • coding_agent.sandbox.endpoint: The Instant Service endpoint. Replace the placeholder ${EAS_SANDBOX_ENDPOINT} with the actual endpoint.

      • coding_agent.sandbox.api_key: The Instant Service API token. Replace the placeholder ${EAS_SANDBOX_API_KEY} with the actual token.

        Note

        Instant Service: Coding Agent Distillation requires Instant Service to provide the sandbox execution environment. In the left-side navigation pane of the PAI console, choose Elastic Algorithm Service (EAS), click the Instant Service tab. After you create the Instant Service, use a public template or a custom template. In the upper-right corner of the template details page, click SDK Access to get the endpoint and the API token used to replace ${EAS_SANDBOX_ENDPOINT} and ${EAS_SANDBOX_API_KEY} in the preceding distillation configuration. For details, see Instant Service - Getting Started.

    • Compute Resource: Set Resource Type to General Computing, set Source to Public Resources, and in Job Resource select a suitable Instance Type, such as ecs.c6.large.

  6. Click Create. Then, in the billing reminder that appears, click OK. The page automatically redirects to the basic configuration page in the task details, where you can track the task status.

Configuration details

The following sections describe the key configuration parameters of the Coding Agent Distillation template. The basic configuration and resource configuration are the same as those for general distillation, so this section lists only the parameters that are specific to this template.

Basic configuration

Basic configuration includes two settings: the task name and the output path. The output path is the root directory for all task outputs. The distillation dataset is also written to this directory, so you do not need to specify a separate dataset output path.

Distillation data build

Teacher model

The Coding Agent Distillation template requires the following teacher models:

No.

Model role

Description

1

Teacher model (required)

Used for both Coding Agent inference and the harness to generate trajectories. Select a model with strong coding capabilities that supports long context and tool calling.

2

Judge model (optional)

Used to assess the quality of Coding Agent trajectories. If you leave this field blank, the teacher model is reused. (Recommended) Specify a separate model.

The teacher model source supports Token Service.

Dataset

Select the input directory. You must select the entire directory, not only a JSONL file. The data must meet the following format requirements:

  • Seed file: seeds.jsonl. Each line contains one seed task with the id, instruction, workspace, test_cmd, and test_files fields.

  • Prepare a workspace archive for each seed. Archive paths are resolved from the relative paths in seeds.jsonl.

  • You must select the entire input directory. If you select only the seeds.jsonl file, the archives are unavailable.

Distillation configuration

The distillation configuration is provided in YAML format and contains the recommended default values from the algorithm team. Adjust the values as needed. The following table describes some parameters that require attention.

Configuration section

Description

dataset

  • input_path (default: seeds.jsonl): The path of the input seed file, in the input mount directory.

  • output_path (default: 04_merged.jsonl): The merged audit snapshot before export, including trajectories that did not pass validation. Used for traceability and preference-pair construction. This file must be separate from the SFT training data file; pointing both to the same file silently overwrites the training data.

  • build_sft.output_path (default: outputs/handoff/03_sft_records.jsonl): Trainable multi-turn SFT data in ShareGPT format, produced by the final build_sft stage.

backend

  • timeout (default: 1200.0): The maximum wait time for a single request, in seconds. The value must cover a response that uses the full max_tokens, not an average-length response.

  • max_retries (default: 3): The number of network-level retries for a single request.

coding_agent.harness

The coding agent harness, which controls agent behavior and sandbox interactions.

  • type (default: cc): The agent harness type. It must match the sandbox image specified by sandbox.template.

  • model (default: deepseek-v4-flash-0731): The model used by the coding agent.

  • max_turns (default: 150): The maximum number of interaction turns for a single seed.

  • timeout (default: 2400): The wall-clock limit for a single seed, in seconds. Configure this parameter together with max_turns, because the agent modifies code and runs tests in the sandbox during each turn.

  • supervisor.hard_abort_elapsed_s (default: 1200): The hard-abort threshold for a single seed, in seconds. The agent is forcibly terminated when its execution exceeds this duration.

coding_agent.sandbox

The remote sandbox configuration. Each seed gets an isolated instance.

  • endpoint (required): The EAS Instant Service endpoint, in the format https://api.<domain>. Replace the placeholder ${EAS_SANDBOX_ENDPOINT} with the actual endpoint.

  • api_key (required): The Instant Service API token, which is separate from the teacher model credential. Replace the placeholder ${EAS_SANDBOX_API_KEY} with the actual token.

  • template (default: coding-agents-harness-cc): The sandbox template name. The template must already exist in your Instant Service.

  • ttl (default: 3600): The sandbox lifetime, in seconds. The sandbox is automatically recycled when it expires.

  • create_concurrency (default: 10): The maximum number of sandboxes created concurrently. When you scale up a batch, adjust this value together with execution.max_workers.

coding_agent.scoring

The validation and scoring mechanism, which controls trajectory quality filtering.

  • require_real_test (default: true): The test_cmd must actually run in the sandbox. LLM-assessed scores are not accepted.

  • require_test_pass (default: true): The test_cmd exit code must be 0. Otherwise, the entire trajectory is discarded.

  • require_modification (default: true): The trajectory must contain actual file modifications. Otherwise, the entire trajectory is discarded.

  • pass_threshold (default: 0.5): The minimum score required to pass validation.

  • enable_judge (default: true): Specifies whether to enable an LLM judge model for auxiliary scoring. The judge model is specified by judge_model.

  • false_positive_check (default: true): Combined anti-cheating checks. Verifies whether test files were modified, whether all test cases were skipped, and whether environment errors were counted as passes.

coding_agent.execution

  • max_workers (default: 10): The seed-level parallelism, which controls the number of seeds that run concurrently.