diff --git a/README.md b/README.md index 4100eac..16a300e 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ async function main() { const instance = await sandbox.create(); - const process4 = await instance.exec("sh", "-c", "cd /app && node server.js"); + const process4 = await instance.exec(["sh", "-c", "cd /app && node server.js"]); const url = await instance.exposePort(3000); console.log(`Server is running at ${url}`); diff --git a/lib/resources/abstraction/sandbox.ts b/lib/resources/abstraction/sandbox.ts index 25af7fa..5e878e4 100644 --- a/lib/resources/abstraction/sandbox.ts +++ b/lib/resources/abstraction/sandbox.ts @@ -12,6 +12,7 @@ import type { PodSandboxCreateDirectoryResponse, PodSandboxListUrlsResponse, PodInstanceData, + ExecOptions, } from "../../types/pod"; import beamClient from "../.."; @@ -430,8 +431,12 @@ export class SandboxInstance extends PodInstance { } /** Run an arbitrary command in the sandbox. */ - public async exec(...args: string[]): Promise { - return this._exec(args); + public async exec( + command: string | string[], + opts?: ExecOptions + ): Promise { + const commandList = Array.isArray(command) ? command : [command]; + return this._exec(commandList, opts); } private async _exec( diff --git a/lib/types/pod.ts b/lib/types/pod.ts index 24784a5..411f528 100644 --- a/lib/types/pod.ts +++ b/lib/types/pod.ts @@ -299,4 +299,9 @@ export interface PodSandboxCreateImageFromFilesystemResponse { imageId: string; } +export interface ExecOptions { + cwd?: string; + env?: Record; +} + // Store requests here?