@lizard-build/cli 4.0.131 → 4.0.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,9 @@ The details behind the Sandboxes section of the core guide. Read the part the ta
12
12
  - [Size and pricing](#size-and-pricing)
13
13
  - [Interactive shell](#interactive-shell)
14
14
  - [Coding agents](#coding-agents)
15
+ - [Docker](#docker)
15
16
  - [Schedules (wake, run, sleep)](#schedules-wake-run-sleep)
17
+ - [Environments (what a new sandbox starts with)](#environments-what-a-new-sandbox-starts-with)
16
18
  - [Desktop (computer use)](#desktop-computer-use)
17
19
  - [Volumes](#volumes)
18
20
  - [Snapshots and pause/resume](#snapshots-and-pauseresume)
@@ -26,7 +28,7 @@ The details behind the Sandboxes section of the core guide. Read the part the ta
26
28
  | `codex`, `claude`, `opencode`, `pi`, `prime` | One coding agent each (Codex, Claude Code, OpenCode, pi, Prime Agent) on Node 22, with git, python3, ripgrep, curl, jq and `lizard`: see [Coding agents](#coding-agents) |
27
29
  | `desktop` | A graphical desktop with Chromium, plus Codex and `lizard`: see [Desktop](#desktop-computer-use) |
28
30
 
29
- A sandbox starts in `us-east-1` unless `--region` names another; with `--volume` or `--snapshot` it starts in their region. An unknown name fails and lists the region's `availableTemplates`. `--with-token` on `sandbox create` signs in the sandbox's own `lizard` with a new key limited to the sandbox's project, deleted with the sandbox (only useful on templates that ship `lizard`).
31
+ Every template in `us-east-1` also has `gh` (GitHub CLI) and Docker: see [Docker](#docker). A sandbox starts in `us-east-1` unless `--region` names another; with `--volume` or `--snapshot` it starts in their region. An unknown name fails and lists the region's `availableTemplates`. `--with-token` on `sandbox create` signs in the sandbox's own `lizard` with a new key limited to the sandbox's project, deleted with the sandbox (only useful on templates that ship `lizard`).
30
32
 
31
33
  `--no-internet` on `sandbox create` starts a sandbox with no internet at all (no outbound TCP, UDP, DNS or ping) for its whole life, its resumes and forks included, and none of its ports can be made public (`sandbox expose` and the desktop are refused); commands and files still work. It is set at create only and cannot be changed later. Not available with a container volume or snapshot. Use it to run untrusted code that must not reach the network.
32
34
 
@@ -133,6 +135,25 @@ error as it is.
133
135
 
134
136
  Use `sandbox exec` to read a log file written by your process.
135
137
 
138
+ ## Docker
139
+
140
+ Sandboxes in `us-east-1` have Docker (engine, `docker compose`, `docker buildx`) and `gh`.
141
+
142
+ ```bash
143
+ lizard sandbox exec <id> -- docker run --rm alpine echo ok
144
+ lizard sandbox exec <id> -- sh -c 'cd /workspace/app && docker compose up -d'
145
+ lizard sandbox expose <id> 8080 # a published container port gets a URL like any other port
146
+ ```
147
+
148
+ - No daemon runs until the first `docker` command, which starts it (about 2 s). It then holds about
149
+ 150 MB of the sandbox's memory, so prefer `small` or larger for real work.
150
+ - A pause keeps files only: the daemon and running containers end; images, volumes and stopped
151
+ containers stay. After a resume the NEXT `docker` command starts the daemon again and brings back
152
+ `restart: always` containers. Until then a published port answers nothing: run `docker ps` once.
153
+ - Works as root and as the sandbox's normal users. Images and containers live on the sandbox's own
154
+ disk and count against its size's disk.
155
+ - `gh` is signed in when the project's environment has GitHub access (see [Environments](#environments-what-a-new-sandbox-starts-with)).
156
+
136
157
  ## Schedules (wake, run, sleep)
137
158
 
138
159
  The platform can wake a paused sandbox on a timer, run a prompt or a shell command in it, and put
@@ -142,15 +163,23 @@ it back to sleep. You pay only while it is awake; files in `/workspace` carry ov
142
163
  # A schedule is set when the sandbox is created (an existing sandbox takes no new one):
143
164
  lizard sandbox create --timeout 0 --every 10m --command "python3 /workspace/job.py"
144
165
  lizard sandbox create -t claude --timeout 0 --every 5m --prompt "Continue the research in /workspace/research; append findings to notes.md"
145
- lizard sandbox create --timeout 0 --cron "0 9 * * mon-fri" --tz Europe/Berlin --command "./report.sh"
166
+ lizard sandbox create --timeout 0 --daily-at 09:00 --weekdays --tz Europe/Berlin --command "./report.sh"
167
+ lizard sandbox create --timeout 0 --cron "0 */6 * * *" --command "./sync.sh"
168
+ lizard sandbox create -e staging --timeout 0 --every 1h --command "./check.sh" # with an environment's variables
146
169
  lizard sandbox schedule <id> --every 10m --command "..." # only in the sandbox's first 15 minutes
147
170
  lizard sandbox schedules [<id>] # list, with next and last run
171
+ lizard sandbox schedule-show <sch_id> # one schedule, with the full prompt or command
172
+ lizard sandbox schedule-runs [-p <project>] # the project's latest runs across all its schedules
173
+ lizard sandbox schedule-runs <sch_id> [-o] # one schedule's history; -o prints the latest output
148
174
  lizard sandbox schedule-run <sch_id> --wait # run now and print the result
149
- lizard sandbox schedule-runs <sch_id> [-o] # history; -o prints the latest output
150
175
  lizard sandbox schedule-set <sch_id> --every 15m | --off | --on
151
176
  lizard sandbox unschedule <sch_id>
152
177
  ```
153
178
 
179
+ - `create --timeout` is the sandbox's lifetime: milliseconds or a duration (`20m`, `2h`); `0` = never
180
+ expires. A schedule's own run limit on create is `--run-timeout`.
181
+ - A `--prompt` schedule set at create runs the template's own agent (`-t claude` → claude) unless
182
+ `--agent` names another; `sandbox schedule <id> --prompt` defaults to codex: pass `--agent`.
154
183
  - Each `--prompt` run starts a NEW agent conversation (on the project's agent credentials, as
155
184
  `sandbox prompt`). Keep state in files: tell the agent to read and update a notes file.
156
185
  - `--command` runs in `/workspace` as root; success = exit code 0. Background processes it leaves
@@ -159,15 +188,66 @@ lizard sandbox unschedule <sch_id>
159
188
  - A sandbox that was already running when a run starts is left running afterwards.
160
189
  - A run still going when the next is due makes that one skip. `--timeout` (default 10m) stops a
161
190
  run. Five failed runs in a row switch the schedule off (`schedules` shows why).
162
- - Environments: a project can hold several named sets of variables (dashboard: Sandboxes →
163
- Environment). `lizard sandbox create -e staging` starts the sandbox with that environment's
164
- variables instead of the project's default ones; an unknown name is refused with the names there are.
165
191
  - Only at creation: a sandbox older than 15 minutes answers `SCHEDULE_ONLY_AT_CREATE` to a new
166
192
  schedule; create a new sandbox with one. Its existing schedules can still be changed, run, deleted.
167
193
  - `--prompt` needs a sandbox with an agent: create it from `-t claude`, `codex`, `opencode`, `pi`
168
194
  or `prime`. The base template has none (`AGENT_NOT_IN_SANDBOX`); `--command` works anywhere.
169
- - Every 1m at most often. Prompt schedules need a key with no scopes (`ACCOUNT_SCOPE_REQUIRED`);
170
- `--command` schedules work with scoped keys. Not on every account yet: `SCHEDULES_NOT_ENABLED`.
195
+ - When: `--every` (1m to 30d), `--daily-at HH:MM` (add `--weekdays` for Monday to Friday), or
196
+ `--cron`; `--tz` is the time zone of the last two (UTC otherwise). One of the three.
197
+ - On `create` the run limit is `--run-timeout` and the label `--schedule-name` (create's own
198
+ `--timeout` is the sandbox's lifetime); on `schedule` / `schedule-set` they are `--timeout` and
199
+ `--name`. Prompt options: `--prompt-file <path>`, `--agent`, `-m <model>`, `--effort`. A run may
200
+ last 6 h at most. `schedule --disabled` creates it switched off.
201
+ - Prompt schedules need a key with no scopes (`ACCOUNT_SCOPE_REQUIRED`); `--command` schedules work
202
+ with scoped keys. A prompt schedule can be changed or run only by whoever created it
203
+ (`SCHEDULE_CREATOR_ONLY`); anyone in the project may switch it off, rename or delete it.
204
+ - At most 50 schedules per account (`SCHEDULE_LIMIT`); the last 200 runs of each are kept. Not on
205
+ every account yet: `SCHEDULES_NOT_ENABLED`.
206
+ - Keep the sandbox from expiring: create it with `--timeout 0`.
207
+
208
+ ## Environments (what a new sandbox starts with)
209
+
210
+ A project's environment is what every sandbox created in it starts with (dashboard: Sandboxes →
211
+ Environment). It has three parts:
212
+
213
+ - **Variables**: in every process of the sandbox. Stored encrypted; they survive pause and resume.
214
+ - **Agent instructions**: a user-level `CLAUDE.md` (Claude Code) and `AGENTS.md` (Codex, OpenCode,
215
+ pi, Prime), 32 KB each, written into the sandbox at create.
216
+ - **GitHub access**: chosen repositories (the first 10) are cloned into `/workspace/<name>` and
217
+ `git` and `gh` are signed in for them, read or write. Set up in the dashboard only.
218
+
219
+ A project can also hold **named environments**: other complete sets of variables. A sandbox
220
+ created with `-e <name>` gets that environment's variables INSTEAD of the default ones, never both.
221
+ Instructions and GitHub access are the project's, whatever the environment.
222
+
223
+ ```bash
224
+ lizard sandbox environments # the project's environments, instructions, GitHub access
225
+ lizard sandbox environment-show [name] [--values] # variable names; --values adds the values
226
+ lizard sandbox environment-set API_URL=https://api.example.com TOKEN=... # the default environment
227
+ lizard sandbox environment-create staging --copy-from default
228
+ lizard sandbox environment-set -e staging API_URL=https://staging.example.com
229
+ lizard sandbox environment-set -e staging --from-file .env.staging # KEY=VALUE lines; # comments, export and quotes are handled
230
+ lizard sandbox environment-unset -e staging OLD_KEY
231
+ lizard sandbox environment-rename staging preview
232
+ lizard sandbox environment-rm preview
233
+ lizard sandbox environment-instructions --claude-md ./CLAUDE.md --agents-md ./AGENTS.md
234
+ lizard sandbox environment-instructions --print claude-md | --clear-agents-md
235
+ lizard sandbox create -e staging # start with the staging variables
236
+ lizard sandbox create --repo owner/name # one repository of your own, instead of the project's
237
+ ```
238
+
239
+ - A change applies to sandboxes created after it; a running sandbox keeps what it started with.
240
+ - `-e` takes the environment's name; an unknown one is refused with the names there are
241
+ (`SANDBOX_ENVIRONMENT_NOT_FOUND`). `-e default` is the same as no `-e`.
242
+ - Every command takes `-p <project>`; without it, the linked project, else the default project.
243
+ - Up to 200 variables per environment (names: letters, digits and `_`; values up to 32 KB) and 20
244
+ named environments per project (names: letters, digits, spaces and `. _ -`, at most 40 characters).
245
+ - Never print values to the user or into a log: `environment-show` lists names only unless `--values`.
246
+ - `create --repo owner/name` (add `--repo-workflows` to let it change `.github/workflows`) gives the
247
+ sandbox write access to that one repository, cloned into `/workspace/<name>`, in place of the
248
+ project's GitHub access. It needs your own GitHub sign-in and a key with no scopes.
249
+ - Not on every account yet: the commands answer `SANDBOX_ENVIRONMENT_NOT_ENABLED`, and creating a
250
+ second environment `SANDBOX_ENVIRONMENTS_NOT_ENABLED`.
171
251
 
172
252
  ## Desktop (computer use)
173
253
 
@@ -0,0 +1,235 @@
1
+ import chalk from "chalk";
2
+ import fs from "node:fs";
3
+ import { Command } from "commander";
4
+ import { api } from "../lib/api.js";
5
+ import { resolveProjectId } from "../lib/config.js";
6
+ import { success, info, isJSONMode, printJSON, table, fail } from "../lib/format.js";
7
+
8
+ // Sandbox environments: what a project's new sandboxes start with (the dashboard's Sandboxes →
9
+ // Environment tab). Server: /api/projects/:id/sandbox-environment (the default environment: its
10
+ // variables, the agents' instruction files, GitHub access) and /sandbox-environments (named
11
+ // environments: variables only). `lizard sandbox create -e <name>` picks one.
12
+
13
+ interface Summary { id: string; name: string; default: boolean; variableCount: number }
14
+ interface Variable { key: string; value: string }
15
+ interface ProjectEnvironment {
16
+ variables: Variable[];
17
+ instructions: { claudeMd: string | null; agentsMd: string | null };
18
+ github: { account: string; access: "read" | "write"; workflows: boolean; enabled: boolean; repos: { id: number; fullName: string }[] } | null;
19
+ }
20
+
21
+ const INSTRUCTIONS_MAX_BYTES = 32_768;
22
+ const isDefault = (name?: string) => !name || name.trim().toLowerCase() === "default";
23
+ const base = (projectId: string) => `/api/projects/${encodeURIComponent(projectId)}/sandbox-environment`;
24
+ const named = (projectId: string, name: string) => `${base(projectId)}s/${encodeURIComponent(name.trim())}`;
25
+
26
+ /** The server answers a bare 404 while the feature is off for the account: say that, not "not found". */
27
+ async function call<T>(run: () => Promise<T>): Promise<T> {
28
+ try {
29
+ return await run();
30
+ } catch (e: any) {
31
+ if (e?.status === 404 && !e?.code && /^not found$/i.test(String(e?.message ?? "").trim())) {
32
+ fail("Sandbox environments are not available on this account yet", 1, "SANDBOX_ENVIRONMENT_NOT_ENABLED");
33
+ }
34
+ throw e;
35
+ }
36
+ }
37
+
38
+ /** KEY=VALUE arguments (and --from-file lines) as { KEY: value }. */
39
+ export function parseAssignments(pairs: string[], file?: string): Record<string, string> {
40
+ const out: Record<string, string> = {};
41
+ const take = (line: string, where: string) => {
42
+ const i = line.indexOf("=");
43
+ if (i <= 0) fail(`${where}: expected KEY=VALUE, got "${line.slice(0, 40)}"`, 2, "USAGE");
44
+ out[line.slice(0, i).trim()] = line.slice(i + 1);
45
+ };
46
+ if (file) {
47
+ for (const raw of fs.readFileSync(file, "utf8").split(/\r?\n/)) {
48
+ const line = raw.trim();
49
+ if (!line || line.startsWith("#")) continue;
50
+ const stripped = line.replace(/^export\s+/, "");
51
+ const i = stripped.indexOf("=");
52
+ if (i <= 0) fail(`${file}: expected KEY=VALUE, got "${line.slice(0, 40)}"`, 2, "USAGE");
53
+ // A value in matching quotes is taken without them, as a .env file means it.
54
+ const value = stripped.slice(i + 1).trim().replace(/^(["'])(.*)\1$/, "$2");
55
+ out[stripped.slice(0, i).trim()] = value;
56
+ }
57
+ }
58
+ for (const p of pairs) take(p, "argument");
59
+ return out;
60
+ }
61
+
62
+ const mask = (v: string) => (v.length <= 4 ? "****" : `${v.slice(0, 2)}****${v.slice(-2)}`);
63
+
64
+ function readInstructions(path: string): string {
65
+ const text = fs.readFileSync(path, "utf8");
66
+ if (Buffer.byteLength(text, "utf8") > INSTRUCTIONS_MAX_BYTES) fail(`${path} is larger than ${INSTRUCTIONS_MAX_BYTES / 1024} KB`, 2, "USAGE");
67
+ return text;
68
+ }
69
+
70
+ export function registerSandboxEnvironmentCommands(sb: Command) {
71
+ const project = (c: Command) => c.option("-p, --project <id>", "Project (name, slug, or ID). Defaults to the linked project.");
72
+
73
+ project(sb.command("environments").alias("envs")
74
+ .description("List the project's sandbox environments: the sets of variables a new sandbox can start with (create -e <name>)"))
75
+ .addHelpText("after", `
76
+ A project's new sandboxes start with its environment: variables, the agents' instruction files
77
+ (CLAUDE.md / AGENTS.md) and GitHub access. The Default environment is the project's own; a named
78
+ environment is another complete set of variables, used INSTEAD of the default's when a sandbox is
79
+ created with it. Instructions and GitHub access are the project's, whatever the environment.
80
+
81
+ lizard sandbox environment-create staging --copy-from default
82
+ lizard sandbox environment-set -e staging API_URL=https://staging.example.com
83
+ lizard sandbox create -e staging`)
84
+ .action(async (opts) => {
85
+ const projectId = await resolveProjectId(opts.project);
86
+ const [list, env] = await call(() => Promise.all([
87
+ api.get<{ environments: Summary[]; canCreate: boolean }>(`${base(projectId)}s`),
88
+ api.get<ProjectEnvironment>(base(projectId)),
89
+ ]));
90
+ if (isJSONMode()) {
91
+ return printJSON({
92
+ environments: list.environments, canCreate: list.canCreate,
93
+ instructions: { claudeMd: env.instructions.claudeMd !== null, agentsMd: env.instructions.agentsMd !== null },
94
+ github: env.github ? { account: env.github.account, access: env.github.access, enabled: env.github.enabled, repos: env.github.repos.map((r) => r.fullName) } : null,
95
+ });
96
+ }
97
+ table(["environment", "variables"], list.environments.map((e) => [e.default ? `${e.name} ${chalk.dim("(default)")}` : e.name, String(e.variableCount)]));
98
+ const files = [env.instructions.claudeMd !== null && "CLAUDE.md", env.instructions.agentsMd !== null && "AGENTS.md"].filter(Boolean);
99
+ info(chalk.dim(`Agent instructions: ${files.length ? files.join(", ") : "none"}`));
100
+ info(chalk.dim(`GitHub access: ${!env.github ? "not set" : `${env.github.enabled ? env.github.access : "off"}, ${env.github.repos.length} ${env.github.repos.length === 1 ? "repository" : "repositories"} of ${env.github.account}`}`));
101
+ if (!list.canCreate) info(chalk.dim("More than one environment per project is not available on this account yet."));
102
+ });
103
+
104
+ project(sb.command("environment-show").alias("env-show")
105
+ .argument("[name]", "Environment name (default: the project's default environment)")
106
+ .description("Show an environment's variables (values masked; --values prints them)")
107
+ .option("--values", "Print the values in full"))
108
+ .action(async (name: string | undefined, opts) => {
109
+ const projectId = await resolveProjectId(opts.project);
110
+ if (!isDefault(name)) {
111
+ const e = await call(() => api.get<{ id: string; name: string; variables: Variable[] }>(named(projectId, name!)));
112
+ if (isJSONMode()) return printJSON(opts.values ? e : { ...e, variables: e.variables.map((v) => ({ key: v.key })) });
113
+ info(chalk.bold(e.name));
114
+ return printVariables(e.variables, opts.values);
115
+ }
116
+ const env = await call(() => api.get<ProjectEnvironment>(base(projectId)));
117
+ if (isJSONMode()) {
118
+ return printJSON({
119
+ id: "default", name: "Default",
120
+ variables: opts.values ? env.variables : env.variables.map((v) => ({ key: v.key })),
121
+ instructions: { claudeMd: env.instructions.claudeMd !== null, agentsMd: env.instructions.agentsMd !== null },
122
+ github: env.github ? { account: env.github.account, access: env.github.access, workflows: env.github.workflows, enabled: env.github.enabled, repos: env.github.repos.map((r) => r.fullName) } : null,
123
+ });
124
+ }
125
+ info(`${chalk.bold("Default")} ${chalk.dim("(the project's own)")}`);
126
+ printVariables(env.variables, opts.values);
127
+ console.log(`\nAgent instructions CLAUDE.md: ${env.instructions.claudeMd !== null ? "set" : chalk.dim("not set")} AGENTS.md: ${env.instructions.agentsMd !== null ? "set" : chalk.dim("not set")}`);
128
+ if (!env.github) console.log(`GitHub access ${chalk.dim("not set (set it in the dashboard: Sandboxes → Environment)")}`);
129
+ else {
130
+ console.log(`GitHub access ${env.github.enabled ? env.github.access : chalk.yellow("off")}${env.github.workflows ? " + workflows" : ""}, ${env.github.account}`);
131
+ for (const r of env.github.repos) console.log(` ${r.fullName}`);
132
+ }
133
+ });
134
+
135
+ project(sb.command("environment-create").alias("env-create")
136
+ .argument("<name>", "Name: letters, digits, spaces and . _ -, at most 40 characters")
137
+ .description("Create a named environment: another set of variables a sandbox can start with")
138
+ .option("--copy-from <name>", "Start with the variables of another environment (\"default\" or a name)"))
139
+ .action(async (name: string, opts) => {
140
+ const projectId = await resolveProjectId(opts.project);
141
+ const e = await call(() => api.post<{ id: string; name: string; variables: Variable[] }>(`${base(projectId)}s`, { name, ...(opts.copyFrom ? { copyFrom: opts.copyFrom } : {}) }));
142
+ if (isJSONMode()) return printJSON({ id: e.id, name: e.name, variables: e.variables.map((v) => ({ key: v.key })) });
143
+ success(`Environment ${chalk.bold(e.name)} created${e.variables.length ? ` with ${e.variables.length} variable${e.variables.length === 1 ? "" : "s"}` : ""}`);
144
+ info(chalk.dim(` lizard sandbox environment-set -e "${e.name}" KEY=VALUE add variables`));
145
+ info(chalk.dim(` lizard sandbox create -e "${e.name}" start a sandbox with it`));
146
+ });
147
+
148
+ project(sb.command("environment-set").alias("env-set")
149
+ .argument("[assignments...]", "KEY=VALUE ...")
150
+ .description("Set variables in an environment (new sandboxes get them; running ones keep what they started with)")
151
+ .option("-e, --environment <name>", "Environment (default: the project's default environment)")
152
+ .option("--from-file <path>", "Also read KEY=VALUE lines from a file (.env format)"))
153
+ .action(async (pairs: string[], opts) => {
154
+ const changes = parseAssignments(pairs, opts.fromFile);
155
+ if (!Object.keys(changes).length) fail("Nothing to set: give KEY=VALUE or --from-file .env", 2, "USAGE");
156
+ const projectId = await resolveProjectId(opts.project);
157
+ await call(() => api.put(isDefault(opts.environment) ? `${base(projectId)}/variables` : `${named(projectId, opts.environment)}/variables`, changes));
158
+ if (isJSONMode()) return printJSON({ ok: true, environment: isDefault(opts.environment) ? "default" : opts.environment, set: Object.keys(changes) });
159
+ success(`Set ${Object.keys(changes).join(", ")} in ${chalk.bold(isDefault(opts.environment) ? "Default" : opts.environment)}`);
160
+ });
161
+
162
+ project(sb.command("environment-unset").alias("env-unset")
163
+ .argument("<keys...>", "Variable names")
164
+ .description("Remove variables from an environment")
165
+ .option("-e, --environment <name>", "Environment (default: the project's default environment)"))
166
+ .action(async (keys: string[], opts) => {
167
+ const projectId = await resolveProjectId(opts.project);
168
+ const changes = Object.fromEntries(keys.map((k) => [k, null]));
169
+ await call(() => api.put(isDefault(opts.environment) ? `${base(projectId)}/variables` : `${named(projectId, opts.environment)}/variables`, changes));
170
+ if (isJSONMode()) return printJSON({ ok: true, environment: isDefault(opts.environment) ? "default" : opts.environment, removed: keys });
171
+ success(`Removed ${keys.join(", ")} from ${chalk.bold(isDefault(opts.environment) ? "Default" : opts.environment)}`);
172
+ });
173
+
174
+ project(sb.command("environment-rename").alias("env-rename")
175
+ .argument("<name>", "Environment name")
176
+ .argument("<newName>", "New name")
177
+ .description("Rename a named environment"))
178
+ .action(async (name: string, newName: string, opts) => {
179
+ if (isDefault(name)) fail("The default environment cannot be renamed", 2, "USAGE");
180
+ const projectId = await resolveProjectId(opts.project);
181
+ const e = await call(() => api.patch<{ id: string; name: string }>(named(projectId, name), { name: newName }));
182
+ if (isJSONMode()) return printJSON(e);
183
+ success(`Environment renamed to ${chalk.bold(e.name)}`);
184
+ });
185
+
186
+ project(sb.command("environment-rm").alias("env-rm").alias("environment-delete")
187
+ .argument("<name>", "Environment name")
188
+ .description("Delete a named environment (sandboxes already created with it keep their variables)"))
189
+ .action(async (name: string, opts) => {
190
+ if (isDefault(name)) fail("The default environment cannot be deleted; remove its variables with environment-unset", 2, "USAGE");
191
+ const projectId = await resolveProjectId(opts.project);
192
+ await call(() => api.delete(named(projectId, name)));
193
+ if (isJSONMode()) return printJSON({ name, deleted: true });
194
+ success(`Environment ${chalk.bold(name)} deleted`);
195
+ });
196
+
197
+ project(sb.command("environment-instructions").alias("env-instructions")
198
+ .description("Show or set the agents' instruction files every new sandbox of the project gets (CLAUDE.md, AGENTS.md)")
199
+ .option("--claude-md <path>", "Set the user-level CLAUDE.md (Claude Code) from a file")
200
+ .option("--agents-md <path>", "Set the user-level AGENTS.md (Codex, OpenCode, pi, Prime) from a file")
201
+ .option("--clear-claude-md", "Remove CLAUDE.md")
202
+ .option("--clear-agents-md", "Remove AGENTS.md")
203
+ .option("--print <file>", "Print one in full: claude-md or agents-md"))
204
+ .action(async (opts) => {
205
+ const projectId = await resolveProjectId(opts.project);
206
+ const body: Record<string, string | null> = {};
207
+ if (opts.claudeMd) body.claudeMd = readInstructions(opts.claudeMd);
208
+ if (opts.agentsMd) body.agentsMd = readInstructions(opts.agentsMd);
209
+ if (opts.clearClaudeMd) body.claudeMd = null;
210
+ if (opts.clearAgentsMd) body.agentsMd = null;
211
+ if (Object.keys(body).length) {
212
+ await call(() => api.put(`${base(projectId)}/instructions`, body));
213
+ if (isJSONMode()) return printJSON({ ok: true, changed: Object.keys(body) });
214
+ return success(`Agent instructions updated: ${Object.entries(body).map(([k, v]) => `${k === "claudeMd" ? "CLAUDE.md" : "AGENTS.md"} ${v === null ? "removed" : "set"}`).join(", ")}`);
215
+ }
216
+ const env = await call(() => api.get<ProjectEnvironment>(base(projectId)));
217
+ if (opts.print) {
218
+ const which = String(opts.print).toLowerCase().replace(/[^a-z]/g, "");
219
+ if (which !== "claudemd" && which !== "agentsmd") fail("--print takes claude-md or agents-md", 2, "USAGE");
220
+ const text = which === "claudemd" ? env.instructions.claudeMd : env.instructions.agentsMd;
221
+ if (isJSONMode()) return printJSON({ file: which === "claudemd" ? "CLAUDE.md" : "AGENTS.md", text });
222
+ if (text === null) return info("Not set.");
223
+ process.stdout.write(text.endsWith("\n") ? text : text + "\n");
224
+ return;
225
+ }
226
+ if (isJSONMode()) return printJSON({ claudeMd: env.instructions.claudeMd !== null, agentsMd: env.instructions.agentsMd !== null });
227
+ console.log(`CLAUDE.md ${env.instructions.claudeMd !== null ? `${Buffer.byteLength(env.instructions.claudeMd, "utf8")} bytes` : chalk.dim("not set")}`);
228
+ console.log(`AGENTS.md ${env.instructions.agentsMd !== null ? `${Buffer.byteLength(env.instructions.agentsMd, "utf8")} bytes` : chalk.dim("not set")}`);
229
+ });
230
+ }
231
+
232
+ function printVariables(vars: Variable[], values: boolean) {
233
+ if (!vars.length) return info(chalk.dim("No variables."));
234
+ table(["variable", "value"], vars.map((v) => [v.key, values ? v.value : chalk.dim(mask(v.value))]));
235
+ }
@@ -2,6 +2,7 @@ import chalk from "chalk";
2
2
  import fs from "node:fs";
3
3
  import { Command, InvalidArgumentError, Option } from "commander";
4
4
  import { api } from "../lib/api.js";
5
+ import { resolveProjectId } from "../lib/config.js";
5
6
  import { success, info, isJSONMode, printJSON, table, timeAgo, fail } from "../lib/format.js";
6
7
 
7
8
  // Sandbox schedules: the platform wakes a paused sandbox on a timer, runs a prompt (the coding
@@ -29,6 +30,13 @@ function parseDuration(v: string): number {
29
30
  return Number(m[1]) * { s: 1, m: 60, h: 3600, d: 86400 }[(m[2] ?? "s") as "s"];
30
31
  }
31
32
 
33
+ /** --daily-at "09:00" [--weekdays] as the cron the server runs: what the dashboard's "Daily at" makes. */
34
+ export function dailyCron(at: string, weekdays: boolean): string {
35
+ const m = String(at).trim().match(/^([01]?\d|2[0-3]):([0-5]\d)$/);
36
+ if (!m) fail(`--daily-at takes a time as HH:MM (24 h), e.g. 09:00; got "${at}"`, 2, "USAGE");
37
+ return `${Number(m![2])} ${Number(m![1])} * * ${weekdays ? "1-5" : "*"}`;
38
+ }
39
+
32
40
  const when = (s: Schedule) => (s.every ? `every ${s.every}` : `cron ${s.cron}${s.timezone !== "UTC" ? ` (${s.timezone})` : ""}`);
33
41
  const what = (s: Schedule) => {
34
42
  const t = (s.kind === "prompt" ? s.prompt : s.command) ?? "";
@@ -60,7 +68,9 @@ function addTaskOptions(c: Command, forCreate: boolean) {
60
68
  return c
61
69
  .option("--every <interval>", "How often: 1m minimum, e.g. 5m, 1h, 1d")
62
70
  .option("--cron <expr>", 'Cron instead: "m h dom mon dow", e.g. "*/5 * * * *", "0 9 * * mon-fri", @daily')
63
- .option("--tz <zone>", "Time zone for --cron (IANA name, e.g. Europe/Berlin)")
71
+ .option("--daily-at <HH:MM>", "Once a day at this time instead (24 h, in --tz; UTC by default)")
72
+ .option("--weekdays", "With --daily-at: Monday to Friday only")
73
+ .option("--tz <zone>", "Time zone for --daily-at and --cron (IANA name, e.g. Europe/Berlin)")
64
74
  .option("--prompt <text>", "Run the coding agent with this prompt (a new conversation each run)")
65
75
  .option("--prompt-file <path>", "Read the prompt from a file")
66
76
  .option("--command <cmd>", "Run this shell command instead (in /workspace, as root)")
@@ -85,7 +95,9 @@ export function addCreateScheduleOptions(c: Command): Command {
85
95
  return c
86
96
  .option("--every <interval>", "Schedule: wake the sandbox this often and run --command or --prompt (1m minimum, e.g. 5m, 1h, 1d)")
87
97
  .option("--cron <expr>", 'Schedule by cron instead: "m h dom mon dow", e.g. "0 9 * * mon-fri", @daily')
88
- .option("--tz <zone>", "Time zone for --cron (IANA name, e.g. Europe/Berlin)")
98
+ .option("--daily-at <HH:MM>", "Once a day at this time instead (24 h, in --tz; UTC by default)")
99
+ .option("--weekdays", "With --daily-at: Monday to Friday only")
100
+ .option("--tz <zone>", "Time zone for --daily-at and --cron (IANA name, e.g. Europe/Berlin)")
89
101
  .option("--command <cmd>", "Schedule: run this shell command (in /workspace, as root)")
90
102
  .option("--prompt <text>", "Schedule: run the coding agent with this prompt, a new conversation each run (needs an agent template: -t claude, codex, ...)")
91
103
  .option("--prompt-file <path>", "Schedule: read the prompt from a file")
@@ -98,14 +110,15 @@ export function addCreateScheduleOptions(c: Command): Command {
98
110
 
99
111
  /** The schedule a `sandbox create` asked for, checked before anything is created; null: none. */
100
112
  export function createScheduleBody(opts: Record<string, any>): Record<string, unknown> | null {
101
- const timing = !!(opts.every || opts.cron);
113
+ const timing = !!(opts.every || opts.cron || opts.dailyAt);
114
+ if (opts.weekdays && !opts.dailyAt) fail("--weekdays goes with --daily-at HH:MM, e.g. --daily-at 09:00 --weekdays", 2, "USAGE");
102
115
  const task = !!(opts.prompt || opts.promptFile || opts.command);
103
- const extras = ["tz", "agent", "model", "effort", "runTimeout", "scheduleName"].filter((k) => opts[k] !== undefined);
116
+ const extras = ["tz", "weekdays", "agent", "model", "effort", "runTimeout", "scheduleName"].filter((k) => opts[k] !== undefined);
104
117
  if (!timing && !task) {
105
- if (extras.length) fail("These options belong to a schedule: add --every 10m (or --cron) and --command \"...\" (or --prompt)", 2, "USAGE");
118
+ if (extras.length) fail("These options belong to a schedule: add --every 10m (or --daily-at 09:00, or --cron) and --command \"...\" (or --prompt)", 2, "USAGE");
106
119
  return null;
107
120
  }
108
- if (!timing) fail("Say how often the schedule runs: --every 5m, or --cron \"*/5 * * * *\"", 2, "USAGE");
121
+ if (!timing) fail("Say when the schedule runs: --every 5m, --daily-at 09:00, or --cron \"*/5 * * * *\"", 2, "USAGE");
109
122
  if (!task) fail("Say what the schedule runs: --command \"...\" or --prompt \"...\"", 2, "USAGE");
110
123
  return taskBody({ ...opts, timeout: opts.runTimeout, name: opts.scheduleName });
111
124
  }
@@ -130,6 +143,10 @@ function taskBody(opts: Record<string, any>): Record<string, unknown> {
130
143
  const body: Record<string, unknown> = {};
131
144
  if (opts.every) body.every = opts.every;
132
145
  if (opts.cron) body.cron = opts.cron;
146
+ if (opts.dailyAt) {
147
+ if (opts.every || opts.cron) fail("Give one of --every, --daily-at and --cron", 2, "USAGE");
148
+ body.cron = dailyCron(opts.dailyAt, !!opts.weekdays);
149
+ } else if (opts.weekdays) fail("--weekdays goes with --daily-at HH:MM", 2, "USAGE");
133
150
  if (opts.tz) body.timezone = opts.tz;
134
151
  if (opts.promptFile) body.prompt = fs.readFileSync(opts.promptFile, "utf8");
135
152
  if (opts.prompt) body.prompt = opts.prompt;
@@ -169,7 +186,7 @@ Examples:
169
186
  lizard sandbox schedule sb_abc123 --every 10m --command "python3 /workspace/job.py"
170
187
  lizard sandbox schedule sb_abc123 --cron "0 9 * * mon-fri" --tz Europe/Berlin --command "./report.sh"`)
171
188
  .action(async (id: string, opts) => {
172
- if (!opts.every && !opts.cron) fail("Say how often: --every 5m, or --cron \"*/5 * * * *\"", 2, "USAGE");
189
+ if (!opts.every && !opts.cron && !opts.dailyAt) fail("Say when: --every 5m, --daily-at 09:00, or --cron \"*/5 * * * *\"", 2, "USAGE");
173
190
  if (!opts.prompt && !opts.promptFile && !opts.command) fail("Say what to run: --prompt \"...\" or --command \"...\"", 2, "USAGE");
174
191
  const body = taskBody(opts);
175
192
  if (opts.disabled) body.enabled = false;
@@ -249,12 +266,31 @@ Examples:
249
266
  });
250
267
 
251
268
  sb.command("schedule-runs")
252
- .argument("<scheduleId>", "Schedule ID (sch_...)")
253
- .description("Show a schedule's recent runs; --output prints the latest run's output")
269
+ .argument("[scheduleId]", "Schedule ID (sch_...). Without one: the project's latest runs, across its schedules")
270
+ .description("Show a schedule's recent runs, or the project's latest runs across all its schedules; --output prints the latest run's output")
254
271
  .option("-n, --limit <n>", "How many runs", "20")
255
272
  .option("-o, --output", "Print the latest run's output in full")
256
- .action(async (sid: string, opts) => {
257
- const { runs } = await api.get<{ runs: Run[] }>(`/api/sandbox-schedules/${sid}/runs?limit=${Number(opts.limit) || 20}`);
273
+ .option("-p, --project <id>", "Without a schedule ID: this project (name, slug, or ID) instead of the linked one")
274
+ .action(async (sid: string | undefined, opts) => {
275
+ const limit = Math.min(Math.max(Number(opts.limit) || 20, 1), 200);
276
+ if (!sid) {
277
+ // What the dashboard's Schedules tab shows: every schedule of the project, their runs merged.
278
+ const projectId = await resolveProjectId(opts.project);
279
+ const { schedules } = await api.get<{ schedules: Schedule[] }>(`/api/sandbox-schedules?projectId=${encodeURIComponent(projectId)}`);
280
+ const per = await Promise.all(schedules.map((s) =>
281
+ api.get<{ runs: Run[] }>(`/api/sandbox-schedules/${s.id}/runs?limit=${Math.min(limit, 20)}`).then((r) => r.runs.map((run) => ({ run, schedule: s })), () => [])));
282
+ const rows = per.flat().sort((x, y) => Date.parse(y.run.startedAt) - Date.parse(x.run.startedAt)).slice(0, limit);
283
+ if (isJSONMode()) return printJSON(rows.map(({ run, schedule }) => ({ ...run, scheduleId: schedule.id, sandboxId: schedule.sandboxId })));
284
+ if (!rows.length) return info("No runs yet. A schedule is set when a sandbox is created: lizard sandbox create --every 10m --command \"...\"");
285
+ if (opts.output) return printRun(rows[0].run, true);
286
+ const worked = rows.reduce((n, r) => n + (r.run.durationMs ?? 0), 0);
287
+ table(["started", "sandbox", "ran", "status", "worked", "schedule"], rows.map(({ run, schedule }) => [
288
+ timeAgo(run.startedAt), schedule.sandboxId, what(schedule), runStatus(run.status),
289
+ run.durationMs != null ? `${Math.round(run.durationMs / 1000)}s` : "-", schedule.id,
290
+ ]));
291
+ return info(chalk.dim(`${rows.length} run${rows.length === 1 ? "" : "s"}, ${Math.round(worked / 1000)}s worked in total`));
292
+ }
293
+ const { runs } = await api.get<{ runs: Run[] }>(`/api/sandbox-schedules/${sid}/runs?limit=${limit}`);
258
294
  if (isJSONMode()) return printJSON(runs);
259
295
  if (!runs.length) return info("No runs yet.");
260
296
  if (opts.output) return printRun(runs[0], true);
@@ -14,6 +14,7 @@ import { resolveVolume } from "../lib/volume.js";
14
14
  import { sandboxShell } from "./sandbox-ssh.js";
15
15
  import { startVncTunnel, vncTarget } from "./sandbox-vnc.js";
16
16
  import { registerSandboxAgentCommands } from "./agents.js";
17
+ import { registerSandboxEnvironmentCommands } from "./sandbox-environments.js";
17
18
  import { registerSandboxScheduleCommands, addCreateScheduleOptions, createScheduleBody, scheduleNewSandbox, scheduleLine } from "./sandbox-schedules.js";
18
19
  import { success, info, warn, error, isJSONMode, printJSON, table, statusColor, timeAgo, isTTY } from "../lib/format.js";
19
20
 
@@ -100,9 +101,11 @@ function parseForkTimeout(value: string): number {
100
101
  }
101
102
 
102
103
  function parseTimeoutOption(value: string): number {
103
- const timeout = Number(value);
104
- if (!/^\d+$/.test(value) || !Number.isSafeInteger(timeout) || timeout > 2_147_483_647) {
105
- throw new Error("Timeout must be an integer from 0 to 2147483647 milliseconds");
104
+ // Milliseconds, or a duration as the schedule options take them: 90s, 20m, 2h, 1d.
105
+ const d = value.trim().toLowerCase().match(/^(\d+)\s*(s|m|h|d)$/);
106
+ const timeout = d ? Number(d[1]) * { s: 1000, m: 60_000, h: 3_600_000, d: 86_400_000 }[d[2] as "s"] : Number(value);
107
+ if ((!d && !/^\d+$/.test(value)) || !Number.isSafeInteger(timeout) || timeout > 2_147_483_647) {
108
+ throw new Error("Timeout must be milliseconds from 0 to 2147483647, or a duration like 90s, 20m, 2h (0 = never expires)");
106
109
  }
107
110
  return timeout;
108
111
  }
@@ -182,7 +185,7 @@ export function registerSandbox(program: Command) {
182
185
  .description("Create a sandbox")
183
186
  .option("-t, --template <name>", `Template (${TEMPLATE_HINT}; server validates)`, "base")
184
187
  .addOption(new Option("-s, --size <size>", `Machine size (${SIZE_HINT}); default medium, small on the Pro trial (1 Small, 2 Mini and 2 Nano at a time, US regions only; Medium, Large and Big unlock after the first payment). Mini works only with the ${MINI_TEMPLATES} templates, Nano only with ${NANO_TEMPLATES}`).choices(SANDBOX_SIZES))
185
- .option("--timeout <ms>", "Lifetime in milliseconds; 0 disables expiration (Pro trial: at most 3600000 = 1 hour, and 0 means 1 hour)", parseTimeoutOption, 300_000)
188
+ .option("--timeout <ms>", "Lifetime in milliseconds, or a duration like 20m or 2h; 0 disables expiration (Pro trial: at most 3600000 = 1 hour, and 0 means 1 hour)", parseTimeoutOption, 300_000)
186
189
  .option("--region <code>", `Region to create the sandbox in (default ${DEFAULT_REGION}; with --volume or --snapshot, theirs)`)
187
190
  .option("--snapshot <id>", "Create from a private saved snapshot, at the size it was taken at")
188
191
  .option("--volume <name-or-id>", "Attach a persistent volume")
@@ -202,6 +205,11 @@ Each run wakes the sandbox, runs the command or prompt, and puts it back to slee
202
205
  A prompt needs a sandbox from an agent template (claude, codex, opencode, pi, prime).`)
203
206
  .action(async (opts) => {
204
207
  const scheduleBody = createScheduleBody(opts);
208
+ // A prompt schedule with no --agent runs the agent the sandbox's template ships, not the
209
+ // platform's default (codex), which a claude or pi sandbox does not have.
210
+ if (scheduleBody?.prompt && !scheduleBody.agent && !opts.snapshot && ["claude", "codex", "opencode", "pi", "prime"].includes(opts.template)) {
211
+ scheduleBody.agent = opts.template;
212
+ }
205
213
  // Refused before anything is created: the server only finds out once the sandbox runs.
206
214
  if (scheduleBody?.prompt && !opts.snapshot && ["base", "interpreter"].includes(opts.template)) {
207
215
  throw new Error(`--prompt needs a sandbox with a coding agent, and the '${opts.template}' template has none. Add -t claude (or codex, opencode, pi, prime), or schedule a --command instead.`);
@@ -521,6 +529,7 @@ Examples:
521
529
 
522
530
  registerSandboxAgentCommands(sb);
523
531
  registerSandboxScheduleCommands(sb);
532
+ registerSandboxEnvironmentCommands(sb);
524
533
 
525
534
  sb.command("ssh")
526
535
  .alias("shell")
@@ -762,7 +771,7 @@ Examples:
762
771
 
763
772
  sb.command("restore")
764
773
  .argument("<snapshot-id>", "Saved snapshot ID")
765
- .option("--timeout <ms>", "Lifetime in milliseconds; 0 disables expiration (Pro trial: at most 3600000 = 1 hour, and 0 means 1 hour)", parseTimeoutOption, 300_000)
774
+ .option("--timeout <ms>", "Lifetime in milliseconds, or a duration like 20m or 2h; 0 disables expiration (Pro trial: at most 3600000 = 1 hour, and 0 means 1 hour)", parseTimeoutOption, 300_000)
766
775
  .option("-p, --project <id>", "Project to start it in (name, slug, or ID); a snapshot restores only in its own project, the default")
767
776
  .option("--volume <name-or-id>", "Mount this volume at /workspace (Firecracker snapshot of a sandbox that had no volume; same region)")
768
777
  .description("Start a new sandbox from a private snapshot")
@@ -6,7 +6,7 @@ import os from "node:os";
6
6
  import { spawn } from "node:child_process";
7
7
  import { createPublicKey, verify } from "node:crypto";
8
8
 
9
- export const CURRENT_VERSION = "4.0.131";
9
+ export const CURRENT_VERSION = "4.0.133";
10
10
  const RELEASES_API = "https://api.github.com/repos/lizard-build/lizard-cli/releases/latest";
11
11
  const RELEASE_BASE = "https://github.com/lizard-build/lizard-cli/releases/latest/download";
12
12
 
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { parseAssignments } from "../../src/commands/sandbox-environments.js";
6
+ import { dailyCron, createScheduleBody } from "../../src/commands/sandbox-schedules.js";
7
+
8
+ afterEach(() => vi.restoreAllMocks());
9
+ const exits = () => vi.spyOn(process, "exit").mockImplementation(((c?: number) => { throw new Error(`exit ${c}`); }) as never);
10
+
11
+ describe("sandbox environment-set assignments", () => {
12
+ it("takes KEY=VALUE, keeping = in the value", () => {
13
+ expect(parseAssignments(["A=1", "URL=https://x/?a=b", "EMPTY="])).toEqual({ A: "1", URL: "https://x/?a=b", EMPTY: "" });
14
+ });
15
+ it("reads a .env file: comments, export, quotes; arguments win", () => {
16
+ const f = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "lz-env-")), ".env");
17
+ fs.writeFileSync(f, "# note\nexport A=1\nB=\"two words\"\n\nC='x'\n");
18
+ expect(parseAssignments(["A=9"], f)).toEqual({ A: "9", B: "two words", C: "x" });
19
+ });
20
+ it("refuses an argument that is not KEY=VALUE", () => {
21
+ exits(); vi.spyOn(console, "error").mockImplementation(() => {});
22
+ expect(() => parseAssignments(["JUSTAKEY"])).toThrow("exit 2");
23
+ });
24
+ });
25
+
26
+ describe("sandbox schedule --daily-at", () => {
27
+ it("makes the cron the dashboard's Daily at makes", () => {
28
+ expect(dailyCron("09:00", false)).toBe("0 9 * * *");
29
+ expect(dailyCron("18:30", true)).toBe("30 18 * * 1-5");
30
+ });
31
+ it("refuses a time that is not HH:MM", () => {
32
+ exits(); vi.spyOn(console, "error").mockImplementation(() => {});
33
+ expect(() => dailyCron("9am", false)).toThrow("exit 2");
34
+ });
35
+ it("is a schedule's timing on sandbox create", () => {
36
+ expect(createScheduleBody({ dailyAt: "07:15", weekdays: true, tz: "Europe/Berlin", command: "./report.sh" }))
37
+ .toEqual({ cron: "15 7 * * 1-5", timezone: "Europe/Berlin", command: "./report.sh" });
38
+ });
39
+ it("refuses two timings at once", () => {
40
+ exits(); vi.spyOn(console, "error").mockImplementation(() => {});
41
+ expect(() => createScheduleBody({ every: "5m", dailyAt: "07:15", command: "x" })).toThrow("exit 2");
42
+ });
43
+ });