Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add-vcpus-flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sandbox": patch
---

Add `--vcpus` flag to `create` and `run` commands for configuring sandbox resources.
20 changes: 20 additions & 0 deletions packages/sandbox/src/args/vcpus.ts
Original file line number Diff line number Diff line change
@@ -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)",
});
6 changes: 6 additions & 0 deletions packages/sandbox/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -14,6 +15,7 @@ import { buildNetworkPolicy } from "../util/network-policy";
export const args = {
runtime,
timeout,
vcpus,
ports: cmd.multioption({
long: "publish-port",
short: "p",
Expand Down Expand Up @@ -70,6 +72,7 @@ export const create = cmd.command({
scope,
runtime,
timeout,
vcpus,
silent,
snapshot,
connect,
Expand All @@ -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({
Expand All @@ -94,6 +98,7 @@ export const create = cmd.command({
token: scope.token,
ports,
timeout: ms(timeout),
resources,
networkPolicy,
__interactive: true,
})
Expand All @@ -104,6 +109,7 @@ export const create = cmd.command({
ports,
runtime,
timeout: ms(timeout),
resources,
networkPolicy,
__interactive: true,
});
Expand Down