MSBA-370 · Lesson 6 of 12 · 19 min

Interacting with repositories and environments

▶ Video coming soon A video version of this lesson is on the way.

Dmitri had a habit that the sixth session set out to break. Whenever an agent failed in the cloud, he reran the same task on his laptop in agent mode, where it usually worked, and concluded that the cloud was flaky. Priya asked him to compare the two session logs side by side. On his laptop the agent had used a Node version installed two years earlier, a cached npm folder and a GitHub token with access to every Tidewater repository. In the cloud it had none of those. "It isn't flaky," she said. "It is a different environment. Your job is to make the environment the agent needs, and to know which one it is in."

This lesson covers the GH-600 skill of integrating agents within development environments: evaluating the execution context, scoping an agent to a repository and to branches, invoking an agent from a CI workflow, letting it create branches and pull requests, and handling environment-specific constraints. It also covers safe execution paths: error handling, retries, rollbacks, escalation and traceability.

Execution contexts

An agent's execution context is everything that determines what its tools can do: the machine or container, the operating system and installed software, the files checked out, the network it can reach, the identity and token it uses, and the time it has. Each GitHub agent experience runs in a different context, and evaluating the context is the first step in deciding whether a task will work and whether it is safe.

Evaluating the execution context of local and cloud agents.
QuestionAgent mode or Copilot CLICopilot cloud agent
MachineThe developer's computerA fresh environment powered by GitHub Actions
SoftwareWhatever the developer installedA runner image plus setup steps the repository defines
FilesThe developer's working copy, including uncommitted changesA clone of one repository
NetworkWhatever the developer can reachRestricted by a firewall with an allow list
IdentityThe developer's own credentialsA token scoped to the repository, acting for the person who assigned the task
LifetimeAs long as the developer keeps it openDiscarded after the session

Neither context is better in every way. Local agents are fast to start, can use local tools and see uncommitted work, but they inherit everything the developer can reach, including secrets in environment variables and access to production systems. Cloud agents start from a clean, reproducible state with narrow access, which makes them safer and their results more trustworthy, but they need the repository to describe how to set up the environment.

Setting up the cloud agent's environment

The cloud agent's environment starts from a standard GitHub-hosted runner image. If the project needs particular tools, language versions, dependencies or services, the repository can provide a special GitHub Actions workflow file, .github/workflows/copilot-setup-steps.yml, containing a single job named copilot-setup-steps. Its steps run before the agent starts work. Without it, the agent tries to discover and install what it needs itself, which is slower and less reliable. GitHub's documentation also lets the job choose a larger runner or a self-hosted runner and set a time limit.

A copilot-setup-steps workflow for the trail-units action. The push and pull request triggers let the team test the setup steps like any other workflow. Action versions follow Tidewater's pinned versions from MSBA-302.
name: Copilot setup steps
on:
  workflow_dispatch:
  push:
    paths: [.github/workflows/copilot-setup-steps.yml]
  pull_request:
    paths: [.github/workflows/copilot-setup-steps.yml]
jobs:
  copilot-setup-steps:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-node@v5
        with:
          node-version: 24
          cache: npm
      - run: npm ci

The job name is not a suggestion; GitHub looks for that exact name. The triggers are a convenience Priya liked: because the file is an ordinary workflow, changes to it can be tested on a pull request before the agent depends on them. Dmitri's "flaky" tasks stopped failing the week the file was added, because the agent no longer spent its first minutes guessing which Node version to install.

Scoping an agent to a repository and branches

The cloud agent works in one repository per task. It can read that repository, push only to branches it creates, which GitHub names with a copilot/ prefix, and cannot push to the default branch or to other people's branches. Its work arrives as commits on its branch and, when asked or when the task finishes, as a pull request. Since April 2026 it can also work on a branch without opening a pull request until a person chooses to create one. Branch protection rules and rulesets apply to it like anyone else, and since April 2026 it signs its commits, so it can work in repositories that require signed commits.

A branch diagram. The default branch main runs horizontally. A branch copilot/fix-unit-rounding leaves main, gains three signed commits from the agent and one from a reviewer, and returns to main through a pull request box marked required checks and human approval. A crossed-out arrow shows the agent cannot push directly to main.
The cloud agent's branch scope: its own branch, signed commits, and a pull request that people review and merge.

Agents running locally have no such limits built in. Branch-based scope there comes from the team's conventions and the repository's rules: work on a feature branch, never commit to main, and let rulesets block direct pushes to protected branches for everyone, people and agents alike. Seraphine noted that Skerry's enterprise baseline ruleset, set up in MSBA-291, already prevented direct pushes to default branches, so a local agent misusing a developer's credentials could not push to main either.

Autonomous actions: branches and pull requests

Letting an agent create branches and pull requests is a deliberate decision, made by administrators and repository owners. For Copilot Business and Enterprise, an administrator must enable the cloud agent before anyone can use it, and repository owners can opt repositories out. When it is enabled, anyone with write access to a repository can assign it work, from an issue, from the agents panel on GitHub.com, from Copilot Chat, from Copilot CLI or from supported integrations. The pull request it opens is a draft until it finishes, and GitHub's documented safeguards mean the person who asked for the work cannot be the one who approves it where approval is required, and that GitHub Actions workflows on the agent's pull request do not run until a person allows them.

Worked problem

Choosing the right context

Three tasks arrive. (1) Update the README of the trail-units action to document a new input. (2) Investigate why Owen's print-room PDF build is slow; the typesetter runs only on the print-room machine. (3) Upgrade the validator's test framework to a new major version across many files. Which context should each use?

Show solution
  1. Task 1 is small and fully described, so the cloud agent suits it; it needs no special software.
  2. Task 2 needs software that exists only on one machine, so a local agent on that machine, with approval for every command, is the only option.
  3. Task 3 is large but mechanical and checkable by tests; the cloud agent with setup steps and an approved plan suits it, because the clean environment proves the upgrade works without anyone's local cache.

Agents in CI workflows

The GH-600 outline asks candidates to configure an agent to be invoked in a CI workflow. There are two common patterns. The first is to assign work to the cloud agent from automation: a workflow or script creates an issue and assigns it to Copilot, for example when a nightly dependency check finds a breaking change. The second is to run an agent inside the workflow itself, for example Copilot CLI in non-interactive mode, with a prompt, a narrow set of allowed tools and a token scoped by the workflow's permissions. GitHub has also been previewing agentic workflows written in Markdown that compile to Actions workflows. In every pattern the workflow's own controls apply: permissions on the token, environment protection rules for anything that deploys, and concurrency limits.

An illustration of running Copilot CLI non-interactively in a workflow with limited tools. The CLI options and the kind of token it needs change between versions; check the Copilot CLI documentation before using this pattern.
name: Explain failing build
on:
  workflow_run:
    workflows: [CI]
    types: [completed]
permissions:
  contents: read
  issues: write
jobs:
  explain:
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - name: Ask an agent to diagnose the failure (read-only tools)
        run: |
          copilot -p "Read the failed CI logs for run ${{ github.event.workflow_run.id }}, find the likely cause and write a short diagnosis to diagnosis.md. Do not change source files." \
            --allow-tool 'shell(gh run view)' --allow-tool 'write'
        env:
          GH_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }}
      - run: gh issue create --title "CI failure diagnosis" --body-file diagnosis.md
        env:
          GH_TOKEN: ${{ github.token }}

Environment-specific constraints

Agents meet constraints that people handle without thinking: no internet access in a secure build network, a database that exists only in staging, a licence server that only the print room can reach, a rate limit on an API. The outline asks candidates to configure agents to handle them. The tools are the same as for people: tell the agent about the constraint in the instructions, provide an alternative such as a test double or recorded data, adjust the cloud agent's firewall allow list for destinations it legitimately needs, and make the failure clear when a constraint blocks the task so the agent stops instead of trying workarounds.

Safe execution paths

The last skill in this part of the outline is operating agents with safe execution paths and robust error handling: error handling, retries, rollbacks, escalation and traceability. At Tidewater these became five concrete practices. Errors are returned to the agent as information, as lesson 4 described. Retries are limited, by the controller for transient failures and by instructions for logical ones. Rollback is easy because every change is on a branch: abandoning a session means closing its pull request and deleting its branch, and nothing reaches main without review. Escalation means the agent stops and says what it needs when it is blocked, and someone is notified. Traceability comes from the session log, the signed commits, the pull request history and the audit log entries that record which agent acted for which person.

Local and cloud execution compared

The same task can run locally, in agent mode or Copilot CLI on a developer's machine, or in the cloud agent's environment. The choice shapes what the agent can reach and who is watching. Locally, the agent can use whatever the developer has installed and signed into, which is convenient and risky in equal measure, and the developer usually watches each step. In the cloud, the agent sees only what setup steps installed and what the repository allows, and the person reviews the result afterwards. Teams often use both: local agents for exploratory or design-heavy work with a person close by, and the cloud agent for well-specified tasks that can run while people do something else.

Choosing where an agent task runs.
AspectLocal agentCloud agent
EnvironmentDeveloper's machine or dev containerTemporary environment powered by GitHub Actions
CredentialsWhatever the developer hasRepository-scoped token and Copilot environment
NetworkDeveloper's networkBehind the agent firewall
SupervisionPerson watches and approves stepsPerson reviews the result
Best forExploration, design-heavy changesWell-specified tasks that run unattended

Setup steps as documentation

The copilot-setup-steps workflow turned out to have a second use at Tidewater. Because it listed every tool and command the project needed to build and test, it became the most accurate description of the development environment the team had. When a new volunteer joined to help with TrailCheck, Dmitri pointed them to the workflow before the README, because the README had drifted and the workflow was tested every time the agent ran. Keeping one source of truth for setup, and testing it, helped people as much as agents.

Keeping environments in step

Problems arise when the agent's environment and CI differ. A test that passes in the agent's session and fails in CI, or the reverse, wastes a review cycle and erodes trust. Tidewater aligned the two by using the same Node version and the same install command in copilot-setup-steps and in the CI workflow, and by running the setup workflow itself in CI whenever it changed, so that a broken setup was caught before an agent hit it.

Agents and branch rules

Branch rules apply to agents exactly as they apply to people, which is a strength. A ruleset that requires signed commits, linear history or passing checks on the default branch constrains the agent's pull requests without any agent-specific configuration. GitHub's April 2026 change that made the cloud agent sign its commits meant that repositories requiring signed commits no longer had to make an exception for it. Tidewater reviewed its rulesets when it enabled the agent and found nothing to change, which Priya took as a sign that the rules had been designed for the outcome rather than for particular people.

Common mistakes

  • MistakeAssuming a task that works locally will work the same in the cloud.

    InsteadEvaluate the execution context; define the cloud environment with copilot-setup-steps.

  • MistakeNaming the setup job anything you like.

    InsteadThe job must be named copilot-setup-steps in .github/workflows/copilot-setup-steps.yml.

  • MistakeGiving a CI agent the workflow's full write token.

    InsteadGrant the minimum permissions and only the tools the job needs.

  • MistakeLetting an agent work around a blocked network destination.

    InsteadTell it about the constraint, provide alternatives, and adjust the firewall only for legitimate needs.

Summary and key terms

  • The execution context is the machine, software, files, network, identity and lifetime an agent works with.
  • Local agents inherit the developer's access; the cloud agent starts clean with narrow access and a firewall.
  • copilot-setup-steps.yml, with a job of that name, prepares the cloud agent's environment.
  • The cloud agent works in one repository, pushes only to copilot/ branches, signs commits and returns work for human review.
  • Agents can be invoked from CI by assigning work to the cloud agent or running an agent in the workflow; safe paths need error handling, limited retries, rollback, escalation and traceability.
Execution context
The machine, software, files, network, identity and time available to an agent.
copilot-setup-steps.yml
The workflow file whose copilot-setup-steps job prepares the cloud agent's environment.
Branch-based scope
Limiting an agent to working on its own branches.
Escalation path
The way an agent stops and hands a blocked task to a person.
Traceability
The ability to see which agent did what, for whom, and why.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Where must the cloud agent's setup steps live?

    Show answer

    In .github/workflows/copilot-setup-steps.yml, in a job named copilot-setup-steps.

  2. Which branches can the cloud agent push to?

    Show answer

    Only branches it creates, named with the copilot/ prefix.

  3. How is a cloud agent change rolled back before merge?

    Show answer

    Close the pull request and delete its branch.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz