---
title: Build with an agent
description: Give a coding agent what it needs to build on Luna, from the docs as Markdown to a CLI it can script and an environment of its own.
related:
  - /quickstart
  - /develop/manage-environments
  - /platforms/automate-with-api-tokens
---

A coding agent builds on Luna with the same CLI and SDKs you use. It works best when it can read the docs as text, run commands with no one at the keyboard, and deploy somewhere that cannot harm production.

## Start from the quickstart prompt

The [Quickstart](/quickstart) opens with a prompt to copy into your agent. The agent then follows the page for you: it installs the Luna skill, signs you up, creates a project and an environment, and runs `luna dev`.

The prompt's first step installs the skill, which teaches an agent how to define, deploy and call lunas. To install it yourself, run this in your project folder.

```bash
npx skills add gabrieldrl/luna-skills
```

## Point it at the docs as Markdown

Every page of these docs is also served as Markdown. Add `.md` to a page's URL to get it.

| Path | Holds |
| --- | --- |
| `/quickstart` | The page as you read it |
| `/quickstart.md` | The same page as Markdown |
| `/llms.txt` | Every page's title, link and description, grouped as in the sidebar |
| `/llms-full.txt` | Every page in full, in one file |

Give an agent `/llms.txt` to find the right page, then the `.md` of that page to read it.

## Let it script the CLI

Commands that print data take `--json`, and print their answer as JSON on standard output. With `--json`, a command that fails prints its error as JSON on standard error, as an `error` object with `message`, `exitCode`, `status` and `code`.

```bash
luna status --json
```

Every command ends with an exit code that says what kind of failure it met.

| Code | Means |
| --- | --- |
| `0` | Done |
| `1` | Failed for another reason |
| `2` | The command was written wrongly |
| `3` | Not logged in |
| `4` | Not allowed |
| `5` | Not found |
| `6` | Needs `--yes` |

A command that deletes something asks first at a terminal. With no terminal, it stops with exit code 6 instead, and `--yes` lets it go ahead. `luna deploy` asks before a change its preflight flags, and with no terminal it stops and nothing is deployed until you pass `--yes`.

:::warning
`--yes` skips the question that guards against deleting data. Let an agent pass it only in an environment of its own.
:::

## Give it an environment of its own

Make an environment for the agent, so its deploys and test data stay out of production. Run this yourself, logged in as you. `--expires-in` deletes it by itself later.

```bash
luna env create <AGENT_ENV> --expires-in 7d
```

The folder then uses it, and `luna dev` deploys there on every save. `luna dev` never runs against `production`. [Manage environments](/develop/manage-environments) covers copying code and data from another environment.

## Give it a token of its own

The CLI uses the credential in `LUNA_TOKEN` before your own login. Give the agent an API token limited to one project and one environment, with the scopes its work needs and an expiry.

```bash
luna tokens create --project <ORG>/<PROJECT> --env <AGENT_ENV> \
  --scope deploy:write --scope logs:read --expires-in 7d --name agent
```

The token is printed once. Set it in the agent's shell.

```bash
export LUNA_TOKEN=<TOKEN>
```

A token without the scope a command needs is refused with 403, and the command exits with code 4. [Automate with API tokens](/platforms/automate-with-api-tokens) lists every scope.

## Show it your app's API

Luna makes an OpenAPI document for each tenant from the code it runs: every luna type, key and handler, with its routes. An agent writing a client can read it instead of your code, with a token that has `data:read`. [Read a tenant's API](/platforms/read-a-tenants-api) shows where to fetch it.

## Next steps

- [Quickstart](/quickstart) has the prompt to give your agent.
- [Manage environments](/develop/manage-environments) covers environments for each developer and each pull request.
- [Automate with API tokens](/platforms/automate-with-api-tokens) covers scopes, expiry and rotation.
