> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boat.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Repositories

> Clone private or public GitHub repositories into every new sandbox, and find where they land.

Add a repository to an environment. Each new sandbox then clones it into `/home/user/<repository name>`.

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat env add-repo base octocat/hello-world --branch develop
```

> [!NOTE]
>
> Repositories need a GitHub connection on your account. If you signed in with Google or an email code, do these steps:
>
> 1. Open [Dashboard > Environment](https://boat.dev/dashboard?tab=environment).
> 2. Under GitHub repositories, click **Connect GitHub**.
>
> This adds GitHub to the account that you already have. You keep the same way to sign in. Nothing else in boat needs this connection. You can also skip it and use `gh` with your own token inside the sandbox.

> [!WARNING]
>
> A sandbox clones no repository and runs no setup script when one of these is true:
>
> * Its environment is [safe for third parties](https://docs.boat.dev/environments/access.md#safe-for-third-parties).
> * You created it with `--no-env`.
> * The **GitHub repositories** toggle of the environment is off.
>
> Check with `boat exec <id> 'ls /home/user'`.

## Add or remove a repository

Each repository has a base branch and an optional [setup script](https://docs.boat.dev/setup.md#repository-setup-scripts).

* boat clones the base branch as it is. The default is `main`.
* boat never creates a branch for you, also not for forks.
* A repository stays on the base branch until you, or something inside the sandbox, changes it.

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat env add-repo base octocat/hello-world --branch develop
boat env rm-repo base octocat/hello-world
```

```bash curl theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
# $BOAT_API_BASE is https://boat.dev/api/v1
ENV_ID=$(curl -sS "$BOAT_API_BASE/environments" -H "Authorization: Bearer $BOAT_API_KEY" \
  | jq -r '.environments[] | select(.name == "base") | .id')
REPO_ID=$(curl -sS "$BOAT_API_BASE/repos?sync=true&q=hello-world" \
  -H "Authorization: Bearer $BOAT_API_KEY" \
  | jq -r '.installations[0].repositories[0].databaseId')

curl -sS -X POST "$BOAT_API_BASE/environments/$ENV_ID/repos" \
  -H "Authorization: Bearer $BOAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"repositoryId\":\"$REPO_ID\",\"baseBranch\":\"develop\"}"

curl -sS -X DELETE "$BOAT_API_BASE/environments/$ENV_ID/repos/$REPO_ID" \
  -H "Authorization: Bearer $BOAT_API_KEY"
```

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
const { environments } = await sandbox.environments();
const envId = environments.find((e) => e.name === "base")!.id;
const repos = await sandbox.repos({ sync: true, q: "hello-world" });
const repo = repos.installations.flatMap((i) => i.repositories)[0];

await sandbox.addEnvironmentRepo({ environmentId: envId, repositoryId: repo.databaseId, baseBranch: "develop" });
await sandbox.deleteEnvironmentRepo({ environmentId: envId, repositoryId: repo.databaseId });
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
from boat_sdk.models.add_environment_repo_request import AddEnvironmentRepoRequest

env_id = next(e.id for e in sandbox.environments().environments if e.name == "base")
repos = sandbox.repos(sync=True, q="hello-world")
repo = repos.installations[0].repositories[0]

sandbox.add_environment_repo(env_id, AddEnvironmentRepoRequest(repository_id=repo.database_id, base_branch="develop"))
sandbox.delete_environment_repo(env_id, repo.database_id)
```

> [!NOTE]
>
> The older `POST /repos` call (`selectRepo` in the SDKs) changes only the default environment. Use the per-environment calls above instead.

## Where repositories land

The SSH user is `user` and the work directory is `/home/user`. Each folder has the name of the repository, not the `owner/name` pair.

| GitHub repository | Path in the sandbox |
| - | - |
| `acme/web-app` | `/home/user/web-app` |
| `octocat/hello-world` | `/home/user/hello-world` |

| Number of repositories | Project directory for agent tools |
| - | - |
| One | The repository folder |
| Several | `/home/user` is the parent workspace. Each repository is a folder next to the others. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.