doc/user/duo_agent_platform/flows/execution.md
{{< history >}}
{{< /history >}}
Flows use agents to execute tasks.
You can configure the environment where flows use CI/CD to execute. You can also choose to use your own runners, and specify variables in your jobs.
When flows execute in GitLab CI/CD:
By default, flows have network access to the GitLab instance only. For more information about network access rules, see how to configure a network policy. This separate environment protects from unintended consequences of running shell commands.
To prevent flows from running autonomously in the GitLab UI, you can turn off flow execution.
When a flow runs in CI/CD, the runner:
@gitlab/duo-cli package from the npm registry.The executor version is managed by GitLab and updated as part of regular releases.
[!note] The
@gitlab/duo-clinpm package is labeled "Experimental" for standalone CLI usage. When used within flows, the relevant capabilities are covered by the same support level as flows.
You can customize how flows are executed in CI/CD by creating an agent configuration file in your project.
[!note] You cannot use predefined CI/CD variables in this scenario. See the list of available variables.
.gitlab/duo/ folder if it doesn't exist.agent-config.yml.The configuration is applied when flows run in CI/CD for your project.
By default, all flows executed with CI/CD use a standard Docker image provided by GitLab.
This Docker image automatically includes network protection by using
Anthropic Sandbox Runtime (srt).
You can change the Docker image and specify your own instead.
Your own image can be useful for complex projects that require specific dependencies or tools.
If you do this, and you still want to use network protection, make sure to add srt to your
Docker image with your preferred version:
# Install srt sandboxing with cache clearing and verification
ARG SANDBOX_RUNTIME_VERSION=0.0.20
RUN npm cache clean --force && \
npm install -g @anthropic-ai/sandbox-runtime@${SANDBOX_RUNTIME_VERSION} && \
test -s "$(npm root -g)/@anthropic-ai/sandbox-runtime/package.json" && \
srt --version
For more information about SRT and how to install it on a custom image, see remote execution environment sandbox.
To change the default Docker image, add the following to your agent-config.yml file:
image: YOUR_DOCKER_IMAGE
For example:
image: python:3.11-slim
Or for a Node.js project:
image: node:20-alpine
If you use a custom Docker image, ensure that the following commands are available for the agent to function correctly:
gitnpm with a Node.js version compatible with @gitlab/duo-cli. For more information, see GitLab Duo CLI prerequisites.Most base images include these commands by default. However, minimal images (like alpine variants)
might require you to install them explicitly. If needed, you can install missing commands in the
setup script configuration.
[!note] In GitLab 18.9 and earlier, there is a known issue (587996) where flows might fail with newer versions of
gitin custom images. This issue is resolved in@gitlab/duo-cliversion 8.71.0.If you are on
@gitlab/duo-cliversion 8.71.0 or earlier, to avoid flows failing with newer Git versions, you can do either following:
- Use Git version
2.43.7or earlier in your custom image- Use
@gitlab/duo-cliversion 8.71.0.
Additionally, depending on the tool calls made by agents during flow execution, other common utilities may be required.
For example, if you use an Alpine-based image:
image: python:3.11-alpine
setup_script:
- apk add --update git nodejs npm
[!note] When you use a custom Docker image, the environment sandbox is only applied when Anthropic Sandbox Runtime (SRT) is included in your custom image. If SRT is not included, your flow can access any domain reachable from the runner and the full filesystem. If you require network isolation with custom images, install SRT on your image and configure a network policy, or configure network-level controls on your runner (for example, firewall rules or network policies). If you include the
@gitlab-org/duo-clinpm package in your custom image, the flow startup skips the npm download step and reduces job startup time by approximately 15-20 seconds.
You can define setup scripts that run before your flow executes. This is useful for installing dependencies, configuring environments, or performing any necessary initialization.
To add setup scripts, add the following to your agent-config.yml file:
setup_script:
- apt-get update && apt-get install -y curl
- pip install -r requirements.txt
- echo "Setup complete"
These commands:
[!note] The user context for
setup_scriptdepends on the Docker image. The default GitLab image runs asroot. Custom images run as the user defined in the image'sUSERdirective. If yoursetup_scriptrequires root access (for example, to install system packages), ensure your custom image is configured accordingly.
You can configure caching to speed up subsequent flow runs by preserving files and directories between executions. Caching can be useful for dependency folders like node_modules or Python virtual environments.
To cache specific paths, add the following to your agent-config.yml file:
cache:
paths:
- node_modules/
- .npm/
You can use cache keys to create different caches for different scenarios. Cache keys help ensure that the cache is based on your project's state.
cache:
key: my-project-cache
paths:
- vendor/
- .bundle/
Create dynamic cache keys based on file contents (like lock files). When these files change, a new cache is created. This generates a SHA checksum of the specified files:
cache:
key:
files:
- package-lock.json
- yarn.lock
paths:
- node_modules/
Combine a prefix with the SHA computed for the cache key files:
cache:
key:
files:
- package-lock.json
prefix: $CI_JOB_NAME
paths:
- node_modules/
- .npm/
In this example, if the job name is test and the SHA checksum is abc123, the cache key becomes test-abc123.
paths field is required. A cache configuration without paths has no effect.prefix field.Here's an example agent-config.yml file that uses all available options:
# Custom Docker image
image: python:3.11
# Setup script to run before the flow
setup_script:
- apt-get update && apt-get install -y build-essential
- pip install --upgrade pip
- pip install -r requirements.txt
# Cache configuration
cache:
key:
files:
- requirements.txt
- Pipfile.lock
prefix: python-deps
paths:
- .cache/pip
- venv/
# Network configuration
network_policy:
include_recommended_allowed: true
allow_all_unix_sockets: true
allowed_domains:
- my-own-site.com
denied_domains:
- malicious.com
This configuration:
requirements.txt or Pipfile.lock changes, with a prefix of python-deps.Flows that use CI/CD are executed on runners. These runners must:
docker, docker-autoscaler, kubernetes, or others.
The shell executor is not supported.gitlab--duo tag, so the runner knows to pick up the correct jobs.duo_runner_restrictions feature flag.In addition, runners on GitLab Self-Managed:
duo-workflow-svc.runway.gitlab.net on port 443.registry.gitlab.com
or be able to access the Docker image you specified.For GitLab instances with self-signed certificates in the certificate chain, the GitLab Duo CLI requires additional configuration.
[!note] The runner's connection to the GitLab Duo Agent Platform Service is routed through the GitLab instance. Runners do not connect directly to
duo-workflow-svc.runway.gitlab.net. The firewall requirement forduo-workflow-svc.runway.gitlab.neton port443applies to the GitLab instance, not the runner. Your runner network configuration must allow outbound HTTPS traffic to the GitLab instance.
On GitLab.com, flows can use:
[!note] If your top-level group has IP address restrictions enabled, hosted runners cannot be used for flows. Hosted runners use dynamic IP addresses from cloud provider pools that cannot be added to your group's IP allowlist. Instead, configure your own group runner with the
gitlab--duotag at the top-level group level, and ensure its IP address is included in your group's allowlist.
Flows executed on runners can be secured with runtime sandboxing offering network and file system isolation. To benefit from sandboxing you must:
privileged = true in your runner configuration.Privileged mode is required when you want to use the environment sandbox protection. This applies when you use either the default GitLab-provided image or a custom image with SRT installed. If you use a custom Docker image without SRT, privileged mode is not required because the sandbox cannot be applied.
| Configuration | Privileged mode required | Sandbox active |
|---|---|---|
| Default image | Yes | Yes |
| Custom image with SRT | Yes | Yes |
| Custom image without SRT | No | No |