runcloud 0.2.240 → 0.2.243

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.
package/README.md CHANGED
@@ -293,6 +293,20 @@ inventory, not proof of the live guest state.
293
293
  A value can never be passed as a command argument — it would land in your shell
294
294
  history, in `ps` output, and in CI logs. Use a hidden prompt, a file, or stdin.
295
295
 
296
+ ### Keep local logins in secret groups
297
+
298
+ `runcloud credentials` pushes your gcloud, AWS, GitHub and Claude Code logins (or any
299
+ file or command) into secret groups, and keeps them current:
300
+
301
+ ```bash
302
+ runcloud credentials add cloud-dev gcloud
303
+ runcloud credentials push
304
+ runcloud sandbox create --secret-group cloud-dev
305
+ runcloud credentials sync --install # background agent
306
+ ```
307
+
308
+ See [Credentials sync](https://docs.run.cloud/sandboxes/credentials).
309
+
296
310
  ## Custom images
297
311
 
298
312
  A sandbox boots an OCI image. Register your own once, then create sandboxes from
@@ -0,0 +1,494 @@
1
+ import { Option } from 'commander';
2
+ import { existsSync, readFileSync, watch } from 'node:fs';
3
+ import { stat } from 'node:fs/promises';
4
+ import { ApiClient, ApiError, friendlyApiError } from '../api.js';
5
+ import { requireCredentials } from '../config.js';
6
+ import { ask, promptHidden } from '../prompt.js';
7
+ import { addEntry, ConfigError, credentialsConfigPath, loadCredentialsConfig, parseCredentialsConfig, removeEntry, writeCredentialsConfig, } from '../credentials/config.js';
8
+ import { createEngineApi, pushGroups } from '../credentials/engine.js';
9
+ import { readGroup } from '../credentials/items.js';
10
+ import { checkPresetReady, defaultRunCommand, expandPreset } from '../credentials/presets.js';
11
+ import { groupKey, loadState, saveState, withStateLock } from '../credentials/state.js';
12
+ import { acquireAgentLock, appendLog, readLockPid, runAgent } from '../credentials/agent.js';
13
+ import { liveLockHolder } from '../credentials/lockFile.js';
14
+ import { agentLockPath, agentLogPath, agentStatus, installAgent, loginProblemForAgent, uninstallAgent } from '../credentials/install.js';
15
+ import { effectiveOrg } from '../credentials/schedule.js';
16
+ import { buildStatus, printStatus } from '../credentials/status.js';
17
+ import { runClaudeSetupToken, storeClaudeToken } from '../credentials/tokenStore.js';
18
+ const UNSUPPORTED = 'runcloud credentials supports macOS and Linux.';
19
+ const PRE_PUSH_BUDGET_MS = 10_000;
20
+ const PRESET_IDS = ['gcloud', 'aws', 'github', 'claude'];
21
+ function supportedPlatform() {
22
+ return process.platform === 'darwin' || process.platform === 'linux';
23
+ }
24
+ function engineApi() {
25
+ const credentials = requireCredentials();
26
+ return createEngineApi(new ApiClient(credentials.apiUrl, credentials.token));
27
+ }
28
+ function reportConfigError(error) {
29
+ if (!(error instanceof ConfigError))
30
+ return false;
31
+ for (const problem of error.problems)
32
+ console.error(`credentials.yaml: ${problem}`);
33
+ process.exitCode = 1;
34
+ return true;
35
+ }
36
+ async function guarded(fn) {
37
+ if (!supportedPlatform()) {
38
+ console.error(UNSUPPORTED);
39
+ process.exitCode = 1;
40
+ return;
41
+ }
42
+ try {
43
+ await fn();
44
+ }
45
+ catch (error) {
46
+ if (reportConfigError(error))
47
+ return;
48
+ console.error(friendlyApiError(error));
49
+ process.exitCode = 1;
50
+ }
51
+ }
52
+ function loadConfigOrReport() {
53
+ try {
54
+ const config = loadCredentialsConfig();
55
+ if (!config) {
56
+ console.error(`No ${credentialsConfigPath()} yet. Run: runcloud credentials add <group> <preset>`);
57
+ process.exitCode = 1;
58
+ }
59
+ return config;
60
+ }
61
+ catch (error) {
62
+ if (reportConfigError(error))
63
+ return null;
64
+ throw error;
65
+ }
66
+ }
67
+ function stateKeyFor(config, group) {
68
+ return groupKey(effectiveOrg(config, group), group.name);
69
+ }
70
+ function targetOf(item) {
71
+ if (item.kind === 'command' && item.format === 'dotenv')
72
+ return '(variables named in the output)';
73
+ return item.env ?? item.to ?? '(unnamed)';
74
+ }
75
+ function sourceOf(item) {
76
+ return item.kind === 'file' ? item.from : '(command)';
77
+ }
78
+ function describeEntry(entry) {
79
+ if (entry.kind === 'preset') {
80
+ const options = Object.entries(entry.options).map(([k, v]) => ` ${k}=${v}`).join('');
81
+ return `preset ${entry.preset}${options}`;
82
+ }
83
+ if (entry.kind === 'file')
84
+ return `file ${entry.from} → ${targetOf(entry)}`;
85
+ return `(command) → ${targetOf(entry)}`;
86
+ }
87
+ function formatResult(result) {
88
+ switch (result.outcome) {
89
+ case 'pushed':
90
+ return `${result.group}: pushed ${result.pushed.length}, deleted ${result.deleted.length}`;
91
+ case 'unchanged':
92
+ return `${result.group}: unchanged`;
93
+ case 'failed':
94
+ return `${result.group}: failed: ${result.warnings.join('; ')}`;
95
+ case 'not-adopted':
96
+ return `${result.group}: not adopted: run runcloud credentials push --adopt ${result.group}`;
97
+ }
98
+ }
99
+ async function pushAndSave(config, opts) {
100
+ const api = engineApi();
101
+ return withStateLock(async () => {
102
+ const state = loadState();
103
+ const results = await pushGroups(config, state, { api, run: defaultRunCommand }, opts);
104
+ saveState(state);
105
+ return results;
106
+ });
107
+ }
108
+ function buildEntry(preset, opts) {
109
+ const sources = [preset !== undefined, opts.file !== undefined, opts.command !== undefined].filter(Boolean).length;
110
+ if (sources !== 1)
111
+ throw new Error('give exactly one of a preset name, --file, or --command');
112
+ if (preset !== undefined) {
113
+ if (!PRESET_IDS.includes(preset))
114
+ throw new Error(`unknown preset "${preset}" (expected ${PRESET_IDS.join(', ')})`);
115
+ return { preset, ...(opts.profile !== undefined && { profile: opts.profile }) };
116
+ }
117
+ const target = {
118
+ ...(opts.env !== undefined && { env: opts.env }),
119
+ ...(opts.to !== undefined && { to: opts.to }),
120
+ };
121
+ if (opts.file !== undefined)
122
+ return { file: opts.file, ...target };
123
+ return {
124
+ command: opts.command,
125
+ ...target,
126
+ ...(opts.format !== undefined && { format: opts.format }),
127
+ ...(opts.refresh !== undefined && { refresh: opts.refresh }),
128
+ };
129
+ }
130
+ async function confirm(question) {
131
+ return /^y(es)?$/i.test((await ask(question)).trim());
132
+ }
133
+ async function addCommand(group, preset, opts) {
134
+ const entry = buildEntry(preset, opts);
135
+ const existing = existsSync(credentialsConfigPath()) ? readFileSync(credentialsConfigPath(), 'utf8') : null;
136
+ const next = addEntry(existing, group, entry);
137
+ const config = parseCredentialsConfig(next);
138
+ const added = config.groups.find((g) => g.name === group)?.entries.at(-1);
139
+ if (!added)
140
+ throw new Error(`could not add an entry to group "${group}"`);
141
+ if (added.kind === 'preset') {
142
+ if (added.preset !== 'claude') {
143
+ const message = await checkPresetReady(added.preset, added.options, defaultRunCommand);
144
+ if (message) {
145
+ console.error(message);
146
+ process.exitCode = 1;
147
+ return;
148
+ }
149
+ }
150
+ }
151
+ const items = added.kind === 'preset' ? expandPreset(added.preset, added.options) : [added];
152
+ for (const item of items)
153
+ console.log(`${group} ${targetOf(item)} ← ${sourceOf(item)}`);
154
+ if (!opts.yes && !(await confirm(`Push these to group ${group}? [y/N] `))) {
155
+ console.log('Nothing written.');
156
+ return;
157
+ }
158
+ if (added.kind === 'preset' && added.preset === 'claude') {
159
+ await storeClaudeToken(await obtainClaudeToken(opts.paste === true), defaultRunCommand);
160
+ }
161
+ writeCredentialsConfig(next);
162
+ const results = await pushAndSave(config, { groups: [group] });
163
+ for (const result of results)
164
+ console.log(formatResult(result));
165
+ if (results.some((r) => r.outcome === 'failed' || r.outcome === 'not-adopted'))
166
+ process.exitCode = 1;
167
+ }
168
+ async function obtainClaudeToken(paste) {
169
+ if (!paste && process.stdin.isTTY) {
170
+ console.log('Running `claude setup-token`. Finish the sign-in it opens; the token it prints is stored for you.');
171
+ const token = await runClaudeSetupToken();
172
+ if (token)
173
+ return token;
174
+ console.log('Could not read a token from `claude setup-token`.');
175
+ }
176
+ return (await promptHidden('Paste the output of `claude setup-token`: ')).trim();
177
+ }
178
+ async function deleteRemote(org, group, names) {
179
+ const api = engineApi();
180
+ const failed = [];
181
+ for (const name of names) {
182
+ try {
183
+ await api.deleteSecret(org, group, name);
184
+ }
185
+ catch (error) {
186
+ if (!(error instanceof ApiError && error.status === 404)) {
187
+ console.error(`could not delete ${name} from group ${group}: ${friendlyApiError(error)}`);
188
+ failed.push(name);
189
+ }
190
+ }
191
+ }
192
+ return failed;
193
+ }
194
+ async function namesOfEntry(target, index, written) {
195
+ if (!target.entries[index])
196
+ return [];
197
+ const { itemNames } = await readGroup(target, defaultRunCommand);
198
+ const own = itemNames.filter((i) => i.entryIndex === index);
199
+ if (own.every((i) => i.names !== null))
200
+ return own.flatMap((i) => i.names).filter((n) => written[n]);
201
+ const others = itemNames.filter((i) => i.entryIndex !== index);
202
+ if (others.some((i) => i.names === null))
203
+ return null;
204
+ const owned = new Set(others.flatMap((i) => i.names));
205
+ return Object.keys(written).filter((n) => !owned.has(n));
206
+ }
207
+ async function removeCommand(group, indexText, opts) {
208
+ const config = loadConfigOrReport();
209
+ if (!config)
210
+ return;
211
+ const index = indexText === undefined ? undefined : Number(indexText);
212
+ if (indexText !== undefined && !Number.isInteger(index))
213
+ throw new Error(`index "${indexText}" is not a number`);
214
+ await withStateLock(async () => {
215
+ let text;
216
+ try {
217
+ text = removeEntry(readFileSync(credentialsConfigPath(), 'utf8'), group, index);
218
+ }
219
+ catch (error) {
220
+ if (error instanceof ConfigError)
221
+ throw new Error(error.problems.join('; '));
222
+ throw error;
223
+ }
224
+ const target = config.groups.find((g) => g.name === group);
225
+ const key = target ? stateKeyFor(config, target) : groupKey(config.org, group);
226
+ const org = target ? effectiveOrg(config, target) : config.org;
227
+ const state = loadState();
228
+ const written = state.groups[key]?.written ?? {};
229
+ let names;
230
+ if (index === undefined || !target)
231
+ names = index === undefined ? Object.keys(written) : [];
232
+ else {
233
+ const found = await namesOfEntry(target, index, written);
234
+ if (found === null) {
235
+ console.error(`could not tell which secrets entry ${index} of group ${group} pushed: it cannot be read now, and neither can the other entries. `
236
+ + 'Nothing changed; fix the entries and run remove again.');
237
+ process.exitCode = 1;
238
+ return;
239
+ }
240
+ names = found;
241
+ }
242
+ if (!opts.keepRemote && names.length > 0) {
243
+ const failed = await deleteRemote(org, group, names);
244
+ if (failed.length > 0) {
245
+ const deleted = names.filter((n) => !failed.includes(n));
246
+ if (deleted.length === 0)
247
+ console.error(`could not delete ${failed.join(', ')}; nothing changed`);
248
+ else {
249
+ for (const name of deleted)
250
+ delete written[name];
251
+ saveState(state);
252
+ console.error(`could not delete ${failed.join(', ')}; deleted ${deleted.join(', ')}, which the next push re-creates. credentials.yaml is unchanged.`);
253
+ }
254
+ process.exitCode = 1;
255
+ return;
256
+ }
257
+ }
258
+ writeCredentialsConfig(text);
259
+ if (index === undefined)
260
+ delete state.groups[key];
261
+ else
262
+ for (const name of names)
263
+ delete state.groups[key]?.written[name];
264
+ saveState(state);
265
+ console.log(index === undefined ? `Removed group ${group}.` : `Removed entry ${index} from group ${group}.`);
266
+ });
267
+ }
268
+ export async function prePushCredentials(deps = {}) {
269
+ if (!supportedPlatform() || process.env.RUNCLOUD_CREDENTIALS_PUSH === '0')
270
+ return;
271
+ let timer;
272
+ try {
273
+ if (!existsSync(credentialsConfigPath()))
274
+ return;
275
+ const config = loadCredentialsConfig();
276
+ if (!config || config.groups.length === 0)
277
+ return;
278
+ if (liveLockHolder(agentLockPath()) !== null)
279
+ return;
280
+ const api = engineApi();
281
+ const timeout = new Promise((resolve) => {
282
+ timer = setTimeout(() => resolve('timeout'), deps.budgetMs ?? PRE_PUSH_BUDGET_MS);
283
+ });
284
+ const push = withStateLock(async () => {
285
+ const state = loadState();
286
+ const results = await pushGroups(config, state, { api, run: defaultRunCommand });
287
+ saveState(state);
288
+ return results;
289
+ });
290
+ push.catch(() => { });
291
+ const results = await Promise.race([push, timeout]);
292
+ if (results === 'timeout') {
293
+ console.error(`credentials: push did not finish within ${(deps.budgetMs ?? PRE_PUSH_BUDGET_MS) / 1000}s; continuing`);
294
+ return;
295
+ }
296
+ const bad = results.filter((r) => r.outcome === 'failed' || r.outcome === 'not-adopted');
297
+ if (bad.length > 0) {
298
+ const first = bad[0];
299
+ console.error(`credentials: ${bad.length} group(s) not pushed (${first.group}: ${first.warnings[0] ?? first.outcome}); run runcloud credentials status`);
300
+ }
301
+ }
302
+ catch (error) {
303
+ if (error instanceof ConfigError)
304
+ console.error('credentials: credentials.yaml has errors; run runcloud credentials list');
305
+ else
306
+ console.error(`credentials: could not push (${error instanceof Error ? error.message.split('\n')[0] : 'unknown error'}); continuing`);
307
+ }
308
+ finally {
309
+ clearTimeout(timer);
310
+ }
311
+ }
312
+ async function syncCommand(opts) {
313
+ if (opts.install && opts.uninstall) {
314
+ console.error('give one of --install or --uninstall');
315
+ process.exitCode = 1;
316
+ return;
317
+ }
318
+ if (opts.install) {
319
+ const problem = loginProblemForAgent();
320
+ if (problem) {
321
+ console.error(problem);
322
+ process.exitCode = 1;
323
+ return;
324
+ }
325
+ await installAgent(defaultRunCommand);
326
+ console.log(`Installed the credentials agent. Log: ${agentLogPath()}`);
327
+ return;
328
+ }
329
+ if (opts.uninstall) {
330
+ await uninstallAgent(defaultRunCommand);
331
+ console.log('Removed the credentials agent.');
332
+ return;
333
+ }
334
+ const release = acquireAgentLock(agentLockPath());
335
+ if (!release) {
336
+ console.error(`another credentials agent is running (pid ${readLockPid(agentLockPath()) ?? 'unknown'})`);
337
+ process.exitCode = 1;
338
+ return;
339
+ }
340
+ const controller = new AbortController();
341
+ const stop = () => controller.abort();
342
+ process.once('SIGINT', stop);
343
+ process.once('SIGTERM', stop);
344
+ const logPath = agentLogPath();
345
+ const logLine = (line) => {
346
+ if (!opts.logOnly)
347
+ console.log(line);
348
+ appendLog(logPath, line);
349
+ };
350
+ let watchErrorLogged = false;
351
+ try {
352
+ await runAgent({
353
+ loadConfig: () => loadCredentialsConfig(),
354
+ push: (keys, config) => {
355
+ if (!config)
356
+ return Promise.resolve([]);
357
+ return pushAndSave(config, { groups: keys });
358
+ },
359
+ statMtime: async (path) => {
360
+ try {
361
+ return (await stat(path)).mtimeMs;
362
+ }
363
+ catch {
364
+ return null;
365
+ }
366
+ },
367
+ watch: (paths, onChange) => {
368
+ const watchers = paths.flatMap((path) => {
369
+ try {
370
+ const watcher = watch(path, onChange);
371
+ watcher.on('error', () => {
372
+ if (watchErrorLogged)
373
+ return;
374
+ watchErrorLogged = true;
375
+ logLine(`${new Date().toISOString()} file watch error; relying on polling`);
376
+ });
377
+ return [watcher];
378
+ }
379
+ catch {
380
+ return [];
381
+ }
382
+ });
383
+ return () => watchers.forEach((w) => w.close());
384
+ },
385
+ log: logLine,
386
+ signal: controller.signal,
387
+ });
388
+ }
389
+ finally {
390
+ process.off('SIGINT', stop);
391
+ process.off('SIGTERM', stop);
392
+ release();
393
+ }
394
+ }
395
+ export function registerCredentials(program) {
396
+ const credentials = program
397
+ .command('credentials')
398
+ .description('Keep local tool logins (gcloud, aws, gh, Claude) pushed to run.cloud secret groups');
399
+ credentials
400
+ .command('add <group> [preset]')
401
+ .description('add a preset (gcloud, aws, github, claude), a --file, or a --command to a group')
402
+ .option('--profile <profile>', 'aws profile')
403
+ .option('--file <path>', 'push this file')
404
+ .option('--command <cmd>', 'push this command output')
405
+ .option('--to <path>', 'sandbox path for a file secret')
406
+ .option('--env <NAME>', 'environment variable name')
407
+ .option('--format <format>', 'command output format (raw or dotenv)')
408
+ .option('--refresh <duration>', 'how often a command is re-run, for example 30m')
409
+ .option('--yes', 'skip the confirmation')
410
+ .option('--paste', 'for the claude preset: paste the claude setup-token output instead of running it')
411
+ .action((group, preset, opts) => guarded(() => addCommand(group, preset, opts)));
412
+ credentials
413
+ .command('remove <group> [index]')
414
+ .description('remove a group or one entry; deletes what it pushed unless --keep-remote')
415
+ .option('--keep-remote', 'leave the pushed secrets in the org')
416
+ .action((group, index, opts) => guarded(() => removeCommand(group, index, opts)));
417
+ credentials
418
+ .command('list')
419
+ .description('show configured groups and where each entry lands (never values)')
420
+ .option('--json', 'machine-readable output')
421
+ .action((opts) => guarded(async () => {
422
+ const config = loadConfigOrReport();
423
+ if (!config)
424
+ return;
425
+ if (opts.json) {
426
+ const groups = config.groups.map((g) => ({
427
+ group: g.name,
428
+ org: effectiveOrg(config, g),
429
+ entries: g.entries.map((entry, index) => {
430
+ if (entry.kind !== 'command')
431
+ return { index, ...entry };
432
+ const rest = { ...entry };
433
+ delete rest.command;
434
+ return { index, ...rest, source: 'command' };
435
+ }),
436
+ }));
437
+ console.log(JSON.stringify({ groups }, null, 2));
438
+ return;
439
+ }
440
+ if (config.groups.length === 0)
441
+ console.log('No credential groups configured.');
442
+ for (const g of config.groups) {
443
+ console.log(`${g.name}${effectiveOrg(config, g) ? ` (org ${effectiveOrg(config, g)})` : ''}`);
444
+ g.entries.forEach((entry, index) => console.log(` [${index}] ${describeEntry(entry)}`));
445
+ }
446
+ }));
447
+ credentials
448
+ .command('push [groups...]')
449
+ .description('push now')
450
+ .option('--force', 'push even when nothing changed')
451
+ .option('--adopt', 'take over a group that already holds secrets this sync did not write')
452
+ .option('--json', 'machine-readable output')
453
+ .action((groups, opts) => guarded(async () => {
454
+ const config = loadConfigOrReport();
455
+ if (!config)
456
+ return;
457
+ const unknown = groups.filter((name) => !config.groups.some((g) => g.name === name || stateKeyFor(config, g) === name));
458
+ if (unknown.length > 0) {
459
+ for (const name of unknown)
460
+ console.error(`no group "${name}" in credentials.yaml`);
461
+ process.exitCode = 1;
462
+ return;
463
+ }
464
+ const results = await pushAndSave(config, { groups: groups.length > 0 ? groups : undefined, force: opts.force, adopt: opts.adopt });
465
+ if (opts.json)
466
+ console.log(JSON.stringify({ groups: results }, null, 2));
467
+ else
468
+ for (const result of results)
469
+ console.log(formatResult(result));
470
+ if (results.some((r) => r.outcome === 'failed' || r.outcome === 'not-adopted'))
471
+ process.exitCode = 1;
472
+ }));
473
+ credentials
474
+ .command('sync')
475
+ .description('keep pushing in the foreground; --install runs it in the background (launchd or systemd --user)')
476
+ .option('--install', 'install and start the background agent')
477
+ .option('--uninstall', 'stop and remove the background agent')
478
+ .addOption(new Option('--log-only', 'write agent lines to the log file only').hideHelp())
479
+ .action((opts) => guarded(() => syncCommand(opts)));
480
+ credentials
481
+ .command('status')
482
+ .description('last push, next refresh, size and warnings per group')
483
+ .option('--json', 'machine-readable output')
484
+ .action((opts) => guarded(async () => {
485
+ const config = loadConfigOrReport();
486
+ if (!config)
487
+ return;
488
+ const model = buildStatus(config, loadState(), await agentStatus(), loginProblemForAgent());
489
+ if (opts.json)
490
+ console.log(JSON.stringify(model, null, 2));
491
+ else
492
+ printStatus(model);
493
+ }));
494
+ }
@@ -76,7 +76,7 @@ export async function pollImageRegistration(api, ref, opts = {}) {
76
76
  for (;;) {
77
77
  const data = await api.get('/run-cloud/images');
78
78
  const items = (data?.items ?? []);
79
- const row = items.find((item) => item.ref === ref || item.name === ref);
79
+ const row = items.find((item) => (opts.id ? item.id === opts.id : item.name === ref));
80
80
  if (row)
81
81
  opts.onState?.(row.state);
82
82
  if (row && TERMINAL_STATES.has(row.state))
@@ -107,6 +107,7 @@ export function registerImage(program) {
107
107
  const status = opts.json ? undefined : new StatusLine();
108
108
  status?.update(`Building ${opts.ref}`);
109
109
  const finalRow = await pollImageRegistration(api, opts.ref, {
110
+ id: typeof created?.id === 'string' ? created.id : undefined,
110
111
  timeoutMs: opts.timeout * 1000,
111
112
  onState: (state) => status?.update(state === 'building' ? `Building ${opts.ref}` : `${opts.ref} is ${state}`),
112
113
  });
@@ -8,6 +8,7 @@ import { runSandboxCommand, shellCommand } from '../sandboxExec.js';
8
8
  import { runSandboxShell } from '../shellSession.js';
9
9
  import { printJson, StatusLine, style } from '../terminal.js';
10
10
  import { noteDeprecated, registerAccessCommands } from './boxAccess.js';
11
+ import { prePushCredentials } from './credentials.js';
11
12
  import { renderHeldSecrets, renderSandbox, renderSandboxList, } from './sandboxOutput.js';
12
13
  const MAX_SANDBOX_DISK_GIB = 2048;
13
14
  const DEFAULT_SANDBOX_TIMEOUT_SECONDS = 300;
@@ -413,6 +414,7 @@ export function registerSandbox(program) {
413
414
  .option('--no-secrets', 'state explicitly that the sandbox holds no secrets')
414
415
  .option('--tag <key=value>', 'tag the sandbox at create; repeatable. Tag it with whatever id you will have in hand later: that is how you find it again, and tags outlive the sandbox', collectRepeatable, [])
415
416
  .option('--no-wait', 'return before the sandbox finishes building and starting')).action((opts) => run(async () => {
417
+ await prePushCredentials();
416
418
  const exposed = opts.expose !== undefined;
417
419
  if (exposed && !opts.name) {
418
420
  throw new Error('--expose needs --name <name>, the hostname prefix for <name>-box.run.cloud');
@@ -672,6 +674,7 @@ export function registerSandbox(program) {
672
674
  .argument('[id]', 'sandbox id; omit when using --tag')
673
675
  .option('--tag <key=value>', 'find the sandbox by tag instead of id; repeatable, must match exactly one', collectRepeatable, [])
674
676
  .action((id, opts) => run(async () => {
677
+ await prePushCredentials();
675
678
  const credentials = requireCredentials();
676
679
  const api = new ApiClient(credentials.apiUrl, credentials.token);
677
680
  const sandboxId = id ?? (await resolveSandboxByTag(api, opts.tag ?? []));
package/dist/config.js CHANGED
@@ -17,7 +17,7 @@ export function isRunCloud() {
17
17
  || name === 'run-cloud.js'
18
18
  || name === 'run-cloud.ts');
19
19
  }
20
- function credentialsHome() {
20
+ export function credentialsHome() {
21
21
  if (isRunCloud())
22
22
  return process.env.RUN_CLOUD_HOME ?? join(homedir(), '.run-cloud');
23
23
  return process.env.NEWLY_HOME ?? join(homedir(), '.newly');
@@ -64,6 +64,9 @@ export function loadCredentials() {
64
64
  expiresAt: Number.MAX_SAFE_INTEGER,
65
65
  };
66
66
  }
67
+ return loadStoredCredentials();
68
+ }
69
+ export function loadStoredCredentials() {
67
70
  if (!existsSync(credentialsPath()))
68
71
  return null;
69
72
  try {