From 1c230ab35b0fb12fa8a03330a15486c570d1440e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Aug 2026 01:43:56 +0000 Subject: [PATCH 1/2] Initial plan From 325d7e42a555db2f3758c79163c829c8bbf43dc9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Aug 2026 01:55:01 +0000 Subject: [PATCH 2/2] fix: always emit AWF install for behavior-defined engines Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/smoke-pydantic.lock.yml | 104 ++++++++++++++++++ pkg/workflow/behavior_defined_engine.go | 4 +- .../behavior_defined_engine_harness_test.go | 93 ++++++++++++++++ pkg/workflow/nodejs.go | 78 +++++++------ 4 files changed, 243 insertions(+), 36 deletions(-) diff --git a/.github/workflows/smoke-pydantic.lock.yml b/.github/workflows/smoke-pydantic.lock.yml index 2b9d72cd9d4..a0cdf007ca0 100644 --- a/.github/workflows/smoke-pydantic.lock.yml +++ b/.github/workflows/smoke-pydantic.lock.yml @@ -555,6 +555,108 @@ jobs: setupGlobals(core, github, context, exec, io, getOctokit); const { main } = require('${{ runner.temp }}/gh-aw/actions/checkout_pr_branch.cjs'); await main(); + - name: Check KVM availability for docker-sbx + run: | + set -euo pipefail + echo "::group::KVM availability check" + if ! lsmod | grep -q kvm; then + echo "::error::KVM kernel module is not loaded. docker-sbx requires a KVM-capable runner with nested virtualisation enabled." + exit 1 + fi + if ! test -e /dev/kvm; then + echo "::error::/dev/kvm is missing. docker-sbx requires the KVM device to be present on the runner." + exit 1 + fi + echo "KVM is available and /dev/kvm is present ✅" + echo "::endgroup::" + - name: Check Docker Hub secrets for docker-sbx + env: + DOCKER_PAT_VAL: ${{ secrets.DOCKER_PAT }} + DOCKER_USERNAME_VAL: ${{ secrets.DOCKER_USERNAME }} + run: | + set -euo pipefail + echo "::group::Docker Hub secrets check" + if [[ -z "${DOCKER_PAT_VAL}" ]]; then + echo "::error::secrets.DOCKER_PAT is empty. docker-sbx requires a Docker Hub personal access token to pull the sandbox template image. Add a DOCKER_PAT secret to your repository." + exit 1 + fi + if [[ -z "${DOCKER_USERNAME_VAL}" ]]; then + echo "::error::secrets.DOCKER_USERNAME is empty. docker-sbx requires a Docker Hub username. Add a DOCKER_USERNAME secret to your repository." + exit 1 + fi + echo "Docker Hub secrets are present ✅" + echo "::endgroup::" + - name: Install docker-sbx + run: | + set -euo pipefail + echo "::group::Install docker-sbx" + # Add Docker apt repo without installing Docker Engine (already present). + curl -fsSL https://get.docker.com | sudo REPO_ONLY=1 sh + sudo apt-get install -y docker-sbx + sbx version + # Fix KVM permissions so the runner user can create microVMs. + sudo chmod 666 /dev/kvm + echo "docker-sbx installed successfully ✅" + echo "::endgroup::" + - name: Start docker-sbx daemon and authenticate + env: + DOCKER_PAT_VAL: ${{ secrets.DOCKER_PAT }} + DOCKER_USERNAME_VAL: ${{ secrets.DOCKER_USERNAME }} + run: | + set -euo pipefail + export DOCKER_CONFIG="$(mktemp -d)" + trap 'rm -rf "${DOCKER_CONFIG}"' EXIT + echo "::group::Start sbx daemon" + nohup sbx daemon start > /tmp/sbx-daemon.log 2>&1 & + # Poll until daemon is running (up to 10 s). + for i in $(seq 1 10); do + if sbx daemon status 2>/dev/null | grep -q -i running; then + echo "sbx daemon is running" + break + fi + sleep 1 + done + echo "::endgroup::" + echo "::group::Authenticate with Docker Hub" + printf '%s' "${DOCKER_PAT_VAL}" | docker login --username "${DOCKER_USERNAME_VAL}" --password-stdin + printf '%s' "${DOCKER_PAT_VAL}" | sbx login --username "${DOCKER_USERNAME_VAL}" --password-stdin + echo "::endgroup::" + echo "::group::Reset and initialise sbx policy" + sbx daemon stop || true + sbx policy reset --force || true + sbx policy init allow-all + nohup sbx daemon start > /tmp/sbx-daemon.log 2>&1 & + for i in $(seq 1 10); do + if sbx daemon status 2>/dev/null | grep -q -i running; then + echo "sbx daemon restarted" + break + fi + sleep 1 + done + printf '%s' "${DOCKER_PAT_VAL}" | docker login --username "${DOCKER_USERNAME_VAL}" --password-stdin + printf '%s' "${DOCKER_PAT_VAL}" | sbx login --username "${DOCKER_USERNAME_VAL}" --password-stdin + echo "::endgroup::" + echo "::group::Pre-pull sandbox template image" + docker pull docker/sandbox-templates:shell-docker + echo "Template image ready ✅" + echo "::endgroup::" + - name: docker-sbx pre-flight smoke test + run: | + set -euo pipefail + echo "::group::docker-sbx pre-flight smoke test" + sandbox_name="test-sandbox-direct" + cleanup() { + sbx stop "${sandbox_name}" >/dev/null 2>&1 || true + sbx rm --force "${sandbox_name}" >/dev/null 2>&1 || true + } + trap cleanup EXIT + echo "y" | sbx create shell --name "${sandbox_name}" "${GITHUB_WORKSPACE}" + sbx exec "${sandbox_name}" uname -a + sbx stop "${sandbox_name}" + echo "✅ sbx ready" + echo "::endgroup::" + - name: Install AWF binary + run: bash "${RUNNER_TEMP}/gh-aw/actions/install_awf_binary.sh" v0.27.44 - name: Determine automatic lockdown mode for GitHub MCP Server id: determine-automatic-lockdown uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 (source v9) @@ -1567,6 +1669,8 @@ jobs: touch /tmp/gh-aw/threat-detection/detection.log rm -f /tmp/gh-aw/step-summary.md touch /tmp/gh-aw/step-summary.md + - name: Install AWF binary + run: bash "${RUNNER_TEMP}/gh-aw/actions/install_awf_binary.sh" v0.27.44 - name: Write Pydantic AI log parser script if: always() && steps.detection_guard.outputs.run_detection == 'true' continue-on-error: true diff --git a/pkg/workflow/behavior_defined_engine.go b/pkg/workflow/behavior_defined_engine.go index bee3735c76d..9e61ab7e431 100644 --- a/pkg/workflow/behavior_defined_engine.go +++ b/pkg/workflow/behavior_defined_engine.go @@ -179,14 +179,14 @@ func (e *BehaviorDefinedEngine) GetInstallationSteps(workflowData *WorkflowData) // is declared for the engine's CLI itself. if behavior.Installation == nil { if behavior.HarnessScript == "" { - return nil + return buildAWFInstallationSteps(workflowData) } return BuildNpmEngineInstallStepsWithAWF([]GitHubActionStep{GenerateNodeJsSetupStep()}, workflowData) } install := behavior.Installation if install.PackageManager != "npm" { - return nil + return buildAWFInstallationSteps(workflowData) } version := install.Version if workflowData != nil && workflowData.EngineConfig != nil && workflowData.EngineConfig.Version != "" { diff --git a/pkg/workflow/behavior_defined_engine_harness_test.go b/pkg/workflow/behavior_defined_engine_harness_test.go index e1d8cf41355..e4fb9f03d34 100644 --- a/pkg/workflow/behavior_defined_engine_harness_test.go +++ b/pkg/workflow/behavior_defined_engine_harness_test.go @@ -10,6 +10,15 @@ import ( "github.com/stretchr/testify/require" ) +func joinInstallSteps(steps []GitHubActionStep) string { + var b strings.Builder + for _, step := range steps { + b.WriteString(strings.Join(step, "\n")) + b.WriteString("\n") + } + return b.String() +} + // newHarnessEngineDefinition returns a minimal EngineDefinition with harness-script set. func newHarnessEngineDefinition() *EngineDefinition { return &EngineDefinition{ @@ -208,6 +217,90 @@ func TestBehaviorDefinedEngineNoHarnessScript(t *testing.T) { assert.NotContains(t, execStepContent, "GHAW_HARNESS_SCRIPT_EOF", "no harness write step should be present") } +func TestBehaviorDefinedEngineGetInstallationSteps_AWFInstallForNonNpmPaths(t *testing.T) { + firewallWorkflowData := &WorkflowData{ + Name: "test", + NetworkPermissions: &NetworkPermissions{ + Allowed: []string{"defaults"}, + Firewall: &FirewallConfig{Enabled: true}, + }, + } + + t.Run("non_npm_installation_includes_awf_install_step", func(t *testing.T) { + def := &EngineDefinition{ + ID: "pipengine", + DisplayName: "Pip Engine", + Behaviors: &EngineBehaviorDefinition{ + Installation: &EngineInstallationDefinition{ + PackageManager: "pip", + PackageName: "example", + StepName: "Install example", + }, + Execution: &EngineExecutionDefinition{ + CommandName: "example", + StepName: "Execute example", + }, + }, + } + engine, err := NewBehaviorDefinedEngine(def) + require.NoError(t, err) + + steps := engine.GetInstallationSteps(firewallWorkflowData) + require.NotEmpty(t, steps) + installStepsText := joinInstallSteps(steps) + assert.Contains(t, installStepsText, "Install AWF binary") + assert.Contains(t, installStepsText, "install_awf_binary.sh") + }) + + t.Run("no_installation_and_no_harness_includes_awf_install_step", func(t *testing.T) { + def := &EngineDefinition{ + ID: "noinstall", + DisplayName: "No Install", + Behaviors: &EngineBehaviorDefinition{ + Execution: &EngineExecutionDefinition{ + CommandName: "noinstall", + StepName: "Execute noinstall", + }, + }, + } + engine, err := NewBehaviorDefinedEngine(def) + require.NoError(t, err) + + steps := engine.GetInstallationSteps(firewallWorkflowData) + require.NotEmpty(t, steps) + installStepsText := joinInstallSteps(steps) + assert.Contains(t, installStepsText, "Install AWF binary") + assert.Contains(t, installStepsText, "install_awf_binary.sh") + }) + + t.Run("custom_command_still_skips_installation", func(t *testing.T) { + def := &EngineDefinition{ + ID: "pipenginecustom", + DisplayName: "Pip Engine Custom", + Behaviors: &EngineBehaviorDefinition{ + Installation: &EngineInstallationDefinition{ + PackageManager: "pip", + PackageName: "example", + StepName: "Install example", + }, + Execution: &EngineExecutionDefinition{ + CommandName: "example", + StepName: "Execute example", + }, + }, + } + engine, err := NewBehaviorDefinedEngine(def) + require.NoError(t, err) + + steps := engine.GetInstallationSteps(&WorkflowData{ + Name: "test", + NetworkPermissions: firewallWorkflowData.NetworkPermissions, + EngineConfig: &EngineConfig{Command: "custom"}, + }) + assert.Nil(t, steps) + }) +} + // TestBehaviorDefinedEngineRenderMCPConfig verifies that the MCP gateway startup command // is always emitted, even for engines that declare no behaviors.mcp.config-path (e.g. // engines with `mcp: false`). Skipping it would leave the gateway container unstarted diff --git a/pkg/workflow/nodejs.go b/pkg/workflow/nodejs.go index 9a726dfe4fb..17f4148bee2 100644 --- a/pkg/workflow/nodejs.go +++ b/pkg/workflow/nodejs.go @@ -112,6 +112,48 @@ func buildStandardNpmEngineInstallSteps( ) } +func buildAWFInstallationSteps(workflowData *WorkflowData) []GitHubActionStep { + if !isFirewallEnabled(workflowData) { + return nil + } + + var steps []GitHubActionStep + + firewallConfig := getFirewallConfig(workflowData) + agentConfig := getAgentConfig(workflowData) + var awfVersion string + if firewallConfig != nil { + awfVersion = firewallConfig.Version + } + + // gVisor must be installed and registered BEFORE AWF starts the agent container. + if isGVisorRuntime(workflowData) { + steps = append(steps, generateGVisorInstallStep()) + } + + // docker-sbx must be installed, authenticated, and smoke-tested BEFORE AWF + // starts so the microVM runtime is ready when AWF launches the agent. + if isDockerSbxRuntime(workflowData) { + steps = append(steps, generateDockerSbxKVMCheckStep()) + steps = append(steps, generateDockerSbxSecretsCheckStep()) + steps = append(steps, generateDockerSbxInstallStep()) + steps = append(steps, generateDockerSbxAuthAndDaemonStep()) + steps = append(steps, generateDockerSbxPreFlightStep()) + } + + awfInstall := generateAWFInstallationStep(awfVersion, agentConfig) + if len(awfInstall) > 0 { + steps = append(steps, awfInstall) + } + + // Install Docker Compose plugin for ARC/DinD runners where it may not be pre-installed. + if isArcDindTopology(workflowData) { + steps = append(steps, generateDockerComposeInstallStep()) + } + + return steps +} + // BuildNpmEngineInstallStepsWithAWF injects an AWF installation step between the Node.js // setup step and the CLI install steps when the firewall is enabled. This eliminates the // duplicated AWF-injection pattern shared by Claude, Gemini, and Copilot engines. @@ -134,40 +176,8 @@ func BuildNpmEngineInstallStepsWithAWF(npmSteps []GitHubActionStep, workflowData steps = append(steps, npmSteps[0]) // Node.js setup step } - // Inject AWF installation after Node.js setup but before the CLI install steps - if isFirewallEnabled(workflowData) { - firewallConfig := getFirewallConfig(workflowData) - agentConfig := getAgentConfig(workflowData) - var awfVersion string - if firewallConfig != nil { - awfVersion = firewallConfig.Version - } - - // gVisor must be installed and registered BEFORE AWF starts the agent container. - if isGVisorRuntime(workflowData) { - steps = append(steps, generateGVisorInstallStep()) - } - - // docker-sbx must be installed, authenticated, and smoke-tested BEFORE AWF - // starts so the microVM runtime is ready when AWF launches the agent. - if isDockerSbxRuntime(workflowData) { - steps = append(steps, generateDockerSbxKVMCheckStep()) - steps = append(steps, generateDockerSbxSecretsCheckStep()) - steps = append(steps, generateDockerSbxInstallStep()) - steps = append(steps, generateDockerSbxAuthAndDaemonStep()) - steps = append(steps, generateDockerSbxPreFlightStep()) - } - - awfInstall := generateAWFInstallationStep(awfVersion, agentConfig) - if len(awfInstall) > 0 { - steps = append(steps, awfInstall) - } - - // Install Docker Compose plugin for ARC/DinD runners where it may not be pre-installed. - if isArcDindTopology(workflowData) { - steps = append(steps, generateDockerComposeInstallStep()) - } - } + // Inject AWF installation after Node.js setup but before the CLI install steps. + steps = append(steps, buildAWFInstallationSteps(workflowData)...) if len(npmSteps) > 1 { steps = append(steps, npmSteps[1:]...) // CLI installation and subsequent steps