diff --git a/.changeset/add-vcpus-flag.md b/.changeset/add-vcpus-flag.md new file mode 100644 index 0000000..daf41b5 --- /dev/null +++ b/.changeset/add-vcpus-flag.md @@ -0,0 +1,5 @@ +--- +"sandbox": patch +--- + +Add `--vcpus` flag to `create` and `run` commands for configuring sandbox resources. diff --git a/packages/sandbox/src/args/vcpus.ts b/packages/sandbox/src/args/vcpus.ts new file mode 100644 index 0000000..0823bfb --- /dev/null +++ b/packages/sandbox/src/args/vcpus.ts @@ -0,0 +1,20 @@ +import * as cmd from "cmd-ts"; + +export const vcpus = cmd.option({ + long: "vcpus", + type: cmd.optional( + cmd.extendType(cmd.number, { + displayName: "COUNT", + async from(n) { + if (!Number.isInteger(n) || n < 1) { + throw new Error( + `Invalid vCPU count: ${n}. Must be a positive integer.`, + ); + } + return n; + }, + }), + ), + description: + "Number of vCPUs to allocate (each vCPU includes 2048 MB of memory)", +}); diff --git a/packages/sandbox/src/commands/create.ts b/packages/sandbox/src/commands/create.ts index f45b846..635eeab 100644 --- a/packages/sandbox/src/commands/create.ts +++ b/packages/sandbox/src/commands/create.ts @@ -2,6 +2,7 @@ import * as cmd from "cmd-ts"; import { runtime } from "../args/runtime"; import ms from "ms"; import { timeout } from "../args/timeout"; +import { vcpus } from "../args/vcpus"; import chalk from "chalk"; import { scope } from "../args/scope"; import { sandboxClient } from "../client"; @@ -14,6 +15,7 @@ import { buildNetworkPolicy } from "../util/network-policy"; export const args = { runtime, timeout, + vcpus, ports: cmd.multioption({ long: "publish-port", short: "p", @@ -70,6 +72,7 @@ export const create = cmd.command({ scope, runtime, timeout, + vcpus, silent, snapshot, connect, @@ -85,6 +88,7 @@ export const create = cmd.command({ deniedCIDRs, }); + const resources = vcpus ? { vcpus } : undefined; const spinner = silent ? undefined : ora("Creating sandbox...").start(); const sandbox = snapshot ? await sandboxClient.create({ @@ -94,6 +98,7 @@ export const create = cmd.command({ token: scope.token, ports, timeout: ms(timeout), + resources, networkPolicy, __interactive: true, }) @@ -104,6 +109,7 @@ export const create = cmd.command({ ports, runtime, timeout: ms(timeout), + resources, networkPolicy, __interactive: true, });