# update_site_environment

Source: https://modulify.ai/docs/mcp/environment/update-site-environment

Replaces every line of a site's environment and starts a build. Needs a paid plan.

- Title: Change the site environment
- Scope: `config:write`
- Access: Makes changes

Send the whole list every time, in the order the lines run. Each line is one of:

| Line | Shape | What it does |
| --- | --- | --- |
| Install packages | `{ "type": "packages", "packages": ["ffmpeg"] }` | Installs Debian 12 packages with apt. A line holds at most 50 packages. |
| Run command | `{ "type": "command", "command": "..." }` | Runs one shell command as root while the machine image is built. A command holds at most 2,000 characters and fails as soon as any part of it fails. |

An empty list puts the site back on the standard environment, and `undo_site_environment` goes back to the last environment that worked.

Every line is built twice, once for the preview and once for the live site and its publish build. Both start with the same tools: Python 3, `curl`, `make` and `g++`, but not `pip` or `gnupg`. Install whatever a command uses in a `packages` line above it, for example `python3-pip` before `pip install --break-system-packages pandas`. A line cannot use or install `git`, because the preview keeps it turned off. For a headless browser, install `chromium` and launch it from `/usr/bin/chromium` with `playwright-core` or `puppeteer-core`, since their own browser downloads land where the site cannot read them.

Modulify's own base comes first and its own setup comes last, and neither can change. A command cannot change `/app`, Node.js, npm, `setpriv`, `git` or the `appuser` account, setuid permissions are removed, and the preview and the live site both run as `appuser`.

A build takes a few minutes. Read how it went with `get_site_environment`. A build that fails changes nothing, because the machines keep the last build that worked, and the preview only moves to a build it starts on. Saving the same lines again does nothing while they are queued, building or built, and builds them again after a failure. The lines can add at most 2 GB on top of the base, and a build is stopped after 20 minutes. On a paid plan a site holds 20 lines and can be saved 20 times a day. See [Environment](https://modulify.ai/docs/editor/environment).

Pass `linesHash`, the `LinesHash` that `get_site_environment` returned, and a save made after the lines changed, in the **Environment** tab, from chat or from another client, is refused with a `409` reading `The environment changed since it was read, so nothing was saved. Read it again and save your change on top of the lines it holds now!` instead of overwriting that change.

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `projectId` | string | Yes | The site id. |
| `lines` | array of objects | Yes | Every line of the environment, in the order they run. Each one is a `packages` line with its `packages` list or a `command` line with its `command`. Send an empty list to go back to the standard environment. |
| `linesHash` | string | No | The `LinesHash` from `get_site_environment` for the lines this change starts from. When the saved lines changed since, nothing is saved and the call is refused with a `409`. Leave it out to save regardless. |