Mount a Git repository when creating a session so the agent can read code from a specified branch or commit in the sandbox.
Scope
- Git repositories are bound when a session is created. You cannot add or remove them at runtime.
- You can mount multiple repositories in one session, up to 10.
- The console provides the Generic Git repository type for GitLab, Gitee, Bitbucket, Alibaba Cloud Codeup, and other HTTPS Git services.
- When you create a session with a Git repository through the API, you must pass both
sandbox.enable_snapshot=trueand an integersnapshot_persistent_seconds(86400–2592000 seconds). The API does not fill in these fields automatically.
A Git repository can only be bound when the session is created. After creation, the repository URL, mount path, and checkout target cannot be changed. You can update the access token through the API.
Mount in the console
- On the agent details page, click New Session.
- In the Resources section, click + and select Git Repository.
- Enter the repository URL and password or access token, and select a checkout mode. You can leave the token empty for public repositories.
- Repeat the steps to add more repositories. Before creating the session, you can delete a repository card.
- After you add a Git repository, Sandbox persistence is enabled and locked. Set the snapshot retention period.
- Click Create Session.
Fields
| Field | Required | Description |
|---|---|---|
| Repository type | Yes | Fixed to Generic Git repository |
| Repository URL | Yes | HTTPS clone URL. When you use a password or access token, the URL must include the user name, for example https://username@gitlab.com/group/project.git. The URL must not contain a password or token |
| Password or access token | No | Leave empty for public repositories. For private repositories, enter the password or token required by the Git service. To push changes, the token must have write permission |
| Checkout mode | No | Supports branch checkout and commit checkout. For a branch, leave it empty to use the default branch, or enter a branch name such as main or feature/demo. For a commit, enter the full commit SHA |
Validation rules
- The repository URL must be a valid HTTPS URL. HTTP, SSH, and FTP are not supported.
- The repository URL must not contain a password or token.
- Branch names support letters, digits,
.,_,-, and/. Consecutive..is not allowed. A branch name cannot start or end with/. A branch with an invalid format returns 400 when the session is created. - The same repository URL and checkout target cannot be mounted twice. Different branches or commits can be mounted separately.
- The branch or commit must exist in the repository. If the format is valid but the target does not exist, the session may be created and Git preparation fails on the first run.
Mount path
The console generates the mount path automatically, usually /workspace/<repository-name>. A non-default branch may add a branch suffix. The actual path is returned in the session resource information.
The agent accesses the repository by the actual path in tool calls. You can include the path in the system prompt, for example: the repository is located at /workspace/project.
Mount through the API
When creating a session, add the Git repository to the resources array and pass both sandbox.enable_snapshot=true and an integer snapshot_persistent_seconds (86400–2592000 seconds). The API does not fill in these fields automatically:
curl
authorization_token, the url must include the user name, for example https://username@gitlab.com/group/project.git. Pass the password or token only through authorization_token; do not include it in the url.
You can omit authorization_token, mount_path, and checkout:
- Omit
authorization_tokenfor public repositories. - If you omit
mount_path, the server generates a path from the repository name. Use themount_pathin the response as the actual path. A custom path must start with/workspace/, must not be only/workspace/, and must be unique within the session. - If you omit
checkout, the repository default branch is used andcheckoutisnullin the response.
Checkout mode
Both the console and API support branch checkout and commit checkout:
Check out a branch:
Mount multiple repositories
Add multiple Git items to the resources array. Each repository must use a different mount_path. The API allows the same repository URL and checkout target to be mounted at different paths. The console prevents the same repository URL and checkout target from being mounted twice.
Query and update credentials
After the session is created, you can query Git resources through the following APIs:
- Get Session: the
resourcesfield contains the repository URL, mount path, and checkout target. - List Session Resources: lists all resources with pagination.
- Get Session Resource: returns a single resource.
curl
authorization_token. The token cannot be empty, and you cannot update other fields in the same request. Query APIs do not return the token.
Limits
- Git repositories can only be mounted when a session is created. You cannot add them through the runtime resource API or remove them separately.
- The Session update API cannot modify
resources. The repository URL, mount path, and checkout target cannot be changed after creation. Create a new session to use a different repository. - Deleting a session removes the Git repository configuration and credential reference. Archived sessions can still be queried for resource information.
- Sessions with Git repositories must enable sandbox persistence. The snapshot retention period is 1 to 30 days.
- If the first run reports a Git repository preparation failure, retry. If the failure persists, check the repository URL, branch or commit, token permissions, and network reachability.
Security recommendations
- Grant the token the minimum permissions required for the task. Use read-only access to read code and grant write access only when you need to push changes.
- When you use a password or access token, the repository URL must contain the user name. Do not include passwords or tokens in the URL; submit them separately with
authorization_token. - Rotate tokens regularly with the Update Git Repository Credential.
- Query APIs do not return the token, but you still need to protect the token used at creation time.
Related topics
- File upload and mount: upload files and mount them to a session.
- Memory store: keep the agent's working notes across sessions.
- Start a session: specify mounted resources when creating a session.
- Update Git Repository Credential: rotate the access token.