# PostHog Code environments - Docs

An **environment** is how you tell PostHog Code how to set up a repo so the agent can start work in it. There are two types of environments, one for each side of where tasks run.

| Type | Used by | What it controls |
| --- | --- | --- |
| Local environment | [Worktree tasks](/docs/posthog-code/tasks.md#worktree) | A setup script that runs when a worktree is created |
| Cloud environment | [Cloud runs](/docs/posthog-code/cloud-runs.md) | Network access rules and the secrets and environment variables the cloud workspace gets |

Local mode tasks don't use environments. They run on your computer in the repo as it already exists, so nothing needs to be prepared.

## Local environments

[Worktrees](/docs/posthog-code/worktrees.md) run in a different directory than your local checkout, so they don't have the dependencies or files that aren't tracked by git. A local environment fills that gap with a setup script that runs once, when a new worktree is created.

Use it to:

-   Install dependencies
-   Run migrations
-   Start background services
-   Do anything else needed to get coding

Local environments live in the repo, so they're committable and shared with your team. Once one is in place, every new worktree gets a project that's already installed and ready.

You can manage your worktree environments in PostHog Code in the **Settings**.

## Cloud environments

A cloud environment controls how a [cloud run](/docs/posthog-code/cloud-runs.md) is configured: what network it can reach, and what secrets and environment variables get injected into the workspace.

Network access can be configured with three different levels:

-   **Trusted.** A curated allowlist (GitHub, npm, PyPI, and similar).
-   **Full.** Anywhere on the internet.
-   **Custom.** Your own allowlist of domains, optionally with the trusted set included.

Manage cloud environments in PostHog Code under **Settings**.

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better