Skip to content

Agent quickstart

Goal: have an AI agent (Claude Code, Copilot, or any framework that can run a CLI) provision a BC environment, publish an AL extension into it, and read the URL back. The CLI commands take seconds to type; provisioning the env itself takes about 15 minutes. Same product as the portal - different floor.

Why agents work with BCDock

The CLI is the API. Every verb supports --output json, every async operation has --wait, every error has a documented exit code. Agents read --help natively and parse JSON. There is no "agent SDK" to integrate; you give the agent shell access to bcdock and it works.

This is deliberate: the CLI is the primary API tool. Every portal button calls the same public Platform API your agent uses; there are no portal-only endpoints, and every action in the portal has a bcdock command, except creating an API key (it needs a signed-in person) and switching plan (it opens with subscriptions). Two actions are reserved for a signed-in person: creating API keys and adding team members.

1. Mint a scoped API key

In the portal go to Profile → API keys → Create. Pick scopes:

  • env:read + env:write - enough for the standard create / publish / hibernate / delete loop, plus reading per-env usage via bcdock env usage.

Copy the resulting bdk_… token once - you can't view it again. Store it in your secret manager (gh secret set, op create item, pass insert, aws secretsmanager, etc.). Never paste it into agent chat history.

2. Hand the token to your agent

$env:BCDOCK_TOKEN = 'bdk_…'

BCDOCK_TOKEN overrides any stored credentials and never writes to disk - exactly the right shape for ephemeral agent sandboxes.

If the agent has its own secret-injection mechanism (Claude Code project settings, Copilot Workspace secrets, GitHub Actions secrets), use that instead of setting it by hand.

3. Tell the agent what it can do

Drop an AGENTS.md (read by many coding agents, for example OpenAI Codex, GitHub Copilot's coding agent and Cursor), or a CLAUDE.md for Claude Code, into the project the agent works on. The Claude Code guide has the copy-paste block for both and a ready-made Claude skill. The goal of this file is not to enumerate commands - the CLI evolves and a stale list rots faster than it helps. Instead, point the agent at discovery and the conventions every verb shares:

## BCDock - Business Central environments

This project uses BCDock for sandbox BC environments. The CLI is the API.

**Discover the surface yourself, don't guess from prior memory.**
- `bcdock --help` - top-level groups
- `bcdock <group> --help` - verbs within a group (e.g. `bcdock env --help`)
- `bcdock <group> <verb> --help` - flags + examples for a single verb

The reference site at <https://docs.bcdock.io/cli/> has every page auto-generated from the binary; treat it as authoritative if `--help` is unavailable.

**Conventions that apply to every verb:**
- `--output json` (or `-o json`) - machine-readable output for any verb you parse
- `--wait` (+ optional `--wait-timeout`) - block until terminal state instead of polling
- Exit codes - `0` ok, `1` general error (including a failed provisioning, or a timed-out `--wait` on create/resume/hibernate), `3` auth, `4` rate-limited, `5` not-found, `124` a wait gave up (`env wait`, `me export --wait`). Documented at <https://docs.bcdock.io/cli/exit-codes/>; full list with `bcdock --help`.

**Authentication:** read the `BCDOCK_TOKEN` environment variable (already set from a project secret). Don't run `bcdock auth login` - it's interactive. Don't write tokens to disk.

**Typical workflow for this project:** provision an env → pull AL symbols → compile → publish into BC → verify → hibernate when done. Discover the verbs for that flow with `bcdock env --help` and `bcdock al --help`. Hibernation is the right "I'm done" action; deletion (per `bcdock env delete --help`) is destructive and should require an explicit human ask.

Why discovery-first beats a hardcoded list: the CLI gains verbs and flags between releases. A CLAUDE.md that names specific flags will lie to the agent the first time those flags change. --help is always current.

4. End-to-end loop

A complete agent session - create env, build and publish extension, verify, tear down:

# 1. Provision (about 15 min). An agent has no terminal for the picker, so pass
#    a major.minor: BCDock creates the newest build of it with a ready image
#    (bcdock artifacts list --region australiaeast --fast-only lists them)
bcdock env create --name agent-test --version 28.5 --country au --region australiaeast --wait -o json

# 2. Pull AL symbols matching the env's BC version into .alpackages/
bcdock env download-symbols agent-test --out-dir .alpackages

# 3. Compile against the env's bundled alc (cached per platform version)
bcdock al compile --env agent-test --out build/MyExtension.app

# 4. Publish - POST to BC's /dev/apps. Synchronous; returns when install completes.
bcdock env publish agent-test build/MyExtension.app

# 5. Read back the URL the agent should hand to the human
$url = (bcdock env get agent-test -o json | ConvertFrom-Json).webClientUrl
"BC ready at: $url"

# 6. Hibernate when the agent is done (free the pool slot, drop to stored rate)
bcdock env hibernate agent-test --wait

A reasoning agent driving this loop should:

  • Parse exit codes - exit 3 means re-authenticate, exit 5 means the env name didn't resolve, exit 124 means a wait gave up - for bcdock env wait, the status you asked for never came (don't loop forever - back off and tell the human). A provisioning failure exits 1: read bcdock env logs <name> --provisioning. With -o json, every failure is also one JSON object on stderr, with an error code to branch on.
  • Use --output json for any step the next step depends on. The CLI's table format is for humans.
  • Prefer bcdock env wait <n> --status running --timeout 30m over polling env get in a loop. It exits 0 when running, 1 with the environment's error message if provisioning fails, and 124 on timeout.

5. Run long operations in the background

Image builds (~45 min) and pool creation (~20 min) take long enough that an interactive agent session shouldn't block on them. Tell the agent:

Run this in the background and notify me when it's done.

Claude Code's Bash tool accepts run_in_background: true. The agent gets a notification when the command exits and the conversation stays usable.

What's next

Troubleshooting

error: not authenticated (exit 3) - BCDOCK_TOKEN is unset, expired, or revoked. Refresh from the portal.

error: scope insufficient (exit 1) - the API key doesn't carry the scope the verb needs. Check the authentication scopes table and re-mint with the right grants.

Agent can't find bcdock - install on the agent's host with the install script or npm install -g @bcdock/cli for Node-based agent runners.

Provisioning is refused with "no ready image" - that version × country combination has no pre-built image in the region, so it cannot be created there yet. Pick one from bcdock artifacts list --region <region> --fast-only, or request that version: the error prints the command with the version filled in (bcdock artifacts request <version> --country <c>). We build it and reply by email when it can be created. Requests are open from BC 27 onward; an older version is refused with that message. For one, email support@bcdock.io.