diff --git a/CHANGELOG.md b/CHANGELOG.md index 6807d35..0c70d95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,20 @@ This file records user-visible changes to the BoxCompute CLI. GitHub Releases use the same notes and bind them to the exact source commit. +## [0.14.4] - 2026-11-30 + +`bxc sandbox expose` reports unsupported platforms before loading credentials. + +### CLI users + +- The help and error message list the supported platforms. Run `bxc sandbox + expose` on Linux or macOS with an x64 or arm64 runtime. +- Update with `bxc update` or `npm install --global @boxcompute/cli@latest`. + +### Security + +- Unsupported clients exit before loading credentials or requesting a service grant. + ## [0.14.3] - 2026-11-29 The CLI can use saved credentials on native Windows. diff --git a/README.md b/README.md index 27b57c3..a849eee 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ analytics, costs and processes running inside the VM do not count as activity. ### Expose VM services To reach a TCP service running inside a network-enabled VM, keep a foreground -tunnel open locally: +tunnel open on Linux or macOS (x64 or arm64): ```sh # 127.0.0.1:3000 -> VM port 3000 diff --git a/package.json b/package.json index ee5422e..67ee94e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@boxcompute/cli", - "version": "0.14.3", + "version": "0.14.4", "description": "Connect local AI agents to BoxCompute sandboxes", "keywords": [ "boxcompute", diff --git a/skills/boxcompute-sandbox/SKILL.md b/skills/boxcompute-sandbox/SKILL.md index aca8e9f..60d1c83 100644 --- a/skills/boxcompute-sandbox/SKILL.md +++ b/skills/boxcompute-sandbox/SKILL.md @@ -69,7 +69,8 @@ and delete with `bxc sandbox delete SANDBOX_ID --yes`, including on test failure or expiry. Ordinary Sandbox persistence guidance below does not apply to VMs. To let the user reach a TCP service in a running VM, start the server as a -durable remote process, then have the user run this foreground command locally: +durable remote process. The user can run this foreground command on Linux or +macOS (x64 or arm64): ```sh bxc sandbox expose SANDBOX_ID --port 3000 diff --git a/src/cli.ts b/src/cli.ts index 8e4f4c8..ba32089 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -44,7 +44,7 @@ import { type AgentTarget, type HarnessDetection, } from "./skill.js"; -import { openServices, type ServiceMapping } from "./services.js"; +import { openServices, requireServicePlatform, SERVICE_PLATFORMS, type ServiceHost, type ServiceMapping } from "./services.js"; import { runProxy } from "./proxy.js"; import { runSsh } from "./ssh.js"; import { OrcaUsageError, runLocal, runOrca } from "./orca.js"; @@ -90,6 +90,7 @@ Commands: logs Read current or retained sandbox logs exec Execute a program inside a sandbox expose Forward selected TCP ports to local loopback + Requires ${SERVICE_PLATFORMS} preview Open or close a one-hour browser preview URL ssh Open experimental lease-limited SSH upload Upload a local file (up to 8 MiB) @@ -159,6 +160,7 @@ Commands: Execute a program inside a sandbox expose SANDBOX_ID --port [LOCAL:]REMOTE Forward up to 8 TCP ports to 127.0.0.1 + Requires ${SERVICE_PLATFORMS} preview SANDBOX_ID --port PORT Open a one-hour HTTP/WebSocket preview URL for a VM port preview SANDBOX_ID --close PREVIEW_ID Close a preview before it expires @@ -472,6 +474,7 @@ export type CliDependencies = { readSkill?: typeof readSkill; syncManagedSkills?: typeof syncManagedSkills; openServices?: typeof openServices; + serviceHost?: ServiceHost; proxy?: typeof runProxy; ssh?: typeof runSsh; runner?: typeof runRunner; @@ -1270,6 +1273,7 @@ export async function runCli(argv: string[], supplied: CliDependencies = {}): Pr write(io.stdout, sandboxHelp); return 0; } + if (command === "sandbox" && args[0] === "expose") requireServicePlatform(supplied.serviceHost); if (command === "deleted" && !args.length) args.push("list"); const connection = await load(env); diff --git a/src/services.ts b/src/services.ts index 20245b6..07b03c4 100644 --- a/src/services.ts +++ b/src/services.ts @@ -13,6 +13,15 @@ import { fileURLToPath } from "node:url"; import type { ServiceAccessApi, ServiceAccessRequest, ServiceAccessResponse, ServiceCleanup } from "./service-access.js"; export type ServiceMapping = { local: number; remote: number }; +export type ServiceHost = Pick; + +export const SERVICE_PLATFORMS = "Linux or macOS (x64 or arm64)"; + +export function requireServicePlatform({ platform, arch }: ServiceHost = process): void { + if (["linux", "darwin"].includes(platform) && ["x64", "arm64"].includes(arch)) return; + const target = platform === "win32" ? `native Windows (${arch})` : `${platform}/${arch}`; + throw new Error(`bxc sandbox expose is unsupported on ${target}. Run it on ${SERVICE_PLATFORMS}.`); +} const unavailable = () => new Error( "Service access unavailable; no mutation retry was attempted. Any unconfirmed access expires at its original deadline.", @@ -97,8 +106,8 @@ export async function openServices( mappings: readonly ServiceMapping[], signal?: AbortSignal, ) { - if (signal?.aborted || !["linux", "darwin"].includes(process.platform) || !["x64", "arm64"].includes(process.arch) - || mappings.length < 1 || mappings.length > 8 + requireServicePlatform(); + if (signal?.aborted || mappings.length < 1 || mappings.length > 8 || mappings.some((mapping) => Object.keys(mapping).sort().join() !== "local,remote" || !Number.isInteger(mapping.local) || mapping.local < 1 || mapping.local > 65_535 || !Number.isInteger(mapping.remote) || mapping.remote < 1 || mapping.remote > 65_535) diff --git a/test/cli.test.ts b/test/cli.test.ts index eb83b03..9c33ff7 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -14,6 +14,33 @@ function output(stream: PassThrough): string { } describe("bxc CLI", () => { + it("documents the expose platforms in CLI and sandbox help", async () => { + for (const args of [["--help"], ["sandbox", "expose", "--help"]]) { + const io = streams(); + expect(await runCli(args, { io, env: {} })).toBe(0); + const exposeHelp = /^ +expose\b[^\n]*(?:\n {10,}[^\n]+)*/m.exec(output(io.stdout))?.[0]; + expect(exposeHelp).toContain("Linux or macOS (x64 or arm64)"); + } + }); + + it.each([ + ["win32", "x64", "native Windows (x64)"], + ["win32", "arm64", "native Windows (arm64)"], + ["linux", "ia32", "linux/ia32"], + ["freebsd", "x64", "freebsd/x64"], + ] as const)("rejects expose on %s/%s before loading credentials or making requests", + async (platform, arch, target) => { + await expect(runCli(["sandbox", "expose", "sbx_one", "--port", "3000"], { + io: streams(), + env: {}, + serviceHost: { platform, arch }, + loadConnection: async () => { throw new Error("should not load credentials"); }, + fetch: Object.assign(async () => { throw new Error("should not make a request"); }, { preconnect: fetch.preconnect }), + openServices: async () => { throw new Error("should not start forwarding"); }, + })).rejects.toThrow(`bxc sandbox expose is unsupported on ${target}. Run it on Linux or macOS (x64 or arm64).`); + }, + ); + it("parses selected service ports without permitting duplicate listeners or targets", () => { const values = ["--port", "3000", "--port", "8080:80"]; expect(serviceMappings(values)).toEqual([{ local: 3000, remote: 3000 }, { local: 8080, remote: 80 }]); @@ -23,12 +50,18 @@ describe("bxc CLI", () => { expect(() => serviceMappings(["--port", "0"])).toThrow("1 to 65535"); }); - it("keeps expose in the foreground and reports loopback mappings", async () => { + it.each([ + ["linux", "x64"], + ["linux", "arm64"], + ["darwin", "x64"], + ["darwin", "arm64"], + ] as const)("keeps expose in the foreground and reports loopback mappings on %s/%s", async (platform, arch) => { const io = streams(); const observed: unknown[] = []; expect(await runCli(["sandbox", "expose", "sbx_one", "--port", "3000", "--port", "8080:80"], { io, env: {}, + serviceHost: { platform, arch }, loadConnection: async () => ({ url: "https://app.boxcompute.ai", token: "bc_live_test", tokenFile: "/credential" }), syncManagedSkills: async () => [], openServices: async (_client, id, mappings, signal) => { diff --git a/test/services.test.ts b/test/services.test.ts index 20665bc..876055c 100644 --- a/test/services.test.ts +++ b/test/services.test.ts @@ -7,11 +7,23 @@ import { hkdfSync, randomBytes, } from "node:crypto"; -import { unsealServices } from "../src/services.js"; +import { openServices, unsealServices } from "../src/services.js"; import type { ServiceAccessRequest } from "../src/service-access.js"; const generation = "11234567-89ab-4cde-8fab-0123456789ab"; +it.skipIf(process.platform !== "win32")("refuses to launch Windows forwarding before requesting service access", async () => { + const unexpectedRequest = async () => { throw new Error("should not request service access"); }; + const api = { + createServiceAccess: unexpectedRequest, + lookupServiceAccess: unexpectedRequest, + revokeServiceAccess: unexpectedRequest, + }; + await expect(openServices(api, "sbx_one", [{ local: 3000, remote: 3000 }])).rejects.toThrow( + `bxc sandbox expose is unsupported on native Windows (${process.arch}). Run it on Linux or macOS (x64 or arm64).`, + ); +}); + function seal(request: ServiceAccessRequest, change: Record = {}) { const sender = generateKeyPairSync("x25519"); const recipient = createPublicKey({