computesdk 1.10.2 → 1.10.3

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/dist/index.d.mts CHANGED
@@ -132,8 +132,13 @@ interface Sandbox$1 {
132
132
  readonly provider: string;
133
133
  /** Execute code in the sandbox */
134
134
  runCode(code: string, runtime?: Runtime): Promise<CodeResult$1>;
135
- /** Execute shell commands */
136
- runCommand(commandOrArray: string | [string, ...string[]], argsOrOptions?: string[] | RunCommandOptions, maybeOptions?: RunCommandOptions): Promise<CommandResult$1>;
135
+ /**
136
+ * Execute shell command
137
+ *
138
+ * Send raw command string to the sandbox - no preprocessing.
139
+ * The provider/server handles shell invocation and execution details.
140
+ */
141
+ runCommand(command: string, options?: RunCommandOptions): Promise<CommandResult$1>;
137
142
  /** Get information about the sandbox */
138
143
  getInfo(): Promise<SandboxInfo$1>;
139
144
  /** Get URL for accessing the sandbox on a specific port */
@@ -1695,6 +1700,10 @@ interface CommandRunOptions {
1695
1700
  shell?: string;
1696
1701
  /** Run in background (optional) */
1697
1702
  background?: boolean;
1703
+ /** Working directory for the command (optional) */
1704
+ cwd?: string;
1705
+ /** Environment variables (optional) */
1706
+ env?: Record<string, string>;
1698
1707
  }
1699
1708
  /**
1700
1709
  * Run - Resource namespace for executing code and commands
@@ -1740,6 +1749,8 @@ declare class Run {
1740
1749
  * @param options - Execution options
1741
1750
  * @param options.shell - Shell to use (optional)
1742
1751
  * @param options.background - Run in background (optional)
1752
+ * @param options.cwd - Working directory for the command (optional)
1753
+ * @param options.env - Environment variables (optional)
1743
1754
  * @returns Command execution result with stdout, stderr, exit code, and duration
1744
1755
  */
1745
1756
  command(command: string, options?: CommandRunOptions): Promise<CommandResult>;
@@ -2598,12 +2609,14 @@ declare class Sandbox {
2598
2609
  */
2599
2610
  runCodeRequest(code: string, language?: string): Promise<CodeExecutionResponse>;
2600
2611
  /**
2601
- * Execute a shell command (POST /run/command)
2612
+ * Execute a command and get the result
2613
+ * Lower-level method that returns the raw API response
2602
2614
  *
2603
- * @param options - Command options
2604
- * @param options.command - The command to execute
2615
+ * @param options.command - Command to execute
2605
2616
  * @param options.shell - Shell to use (optional)
2606
2617
  * @param options.background - Run in background (optional)
2618
+ * @param options.cwd - Working directory for the command (optional)
2619
+ * @param options.env - Environment variables (optional)
2607
2620
  * @returns Command execution result
2608
2621
  *
2609
2622
  * @example
@@ -2616,6 +2629,8 @@ declare class Sandbox {
2616
2629
  command: string;
2617
2630
  shell?: string;
2618
2631
  background?: boolean;
2632
+ cwd?: string;
2633
+ env?: Record<string, string>;
2619
2634
  }): Promise<RunCommandResponse>;
2620
2635
  /**
2621
2636
  * List files at the specified path
@@ -2891,21 +2906,37 @@ declare class Sandbox {
2891
2906
  language: string;
2892
2907
  }>;
2893
2908
  /**
2894
- * Execute shell command in the sandbox (convenience method)
2909
+ * Execute shell command in the sandbox
2895
2910
  *
2896
- * Delegates to sandbox.run.command() - prefer using that directly for new code.
2911
+ * Sends clean command string to server - no preprocessing or shell wrapping.
2912
+ * The server handles shell invocation, working directory, and backgrounding.
2897
2913
  *
2898
- * @param command - The command to execute (string or array form)
2899
- * @param argsOrOptions - Arguments array or options object
2900
- * @param maybeOptions - Options when using (command, args, options) form
2914
+ * @param command - The command to execute (raw string, e.g., "npm install")
2915
+ * @param options - Execution options
2916
+ * @param options.background - Run in background (server uses goroutines)
2917
+ * @param options.cwd - Working directory (server uses cmd.Dir)
2918
+ * @param options.env - Environment variables (server uses cmd.Env)
2901
2919
  * @returns Command execution result
2920
+ *
2921
+ * @example
2922
+ * ```typescript
2923
+ * // Simple command
2924
+ * await sandbox.runCommand('ls -la')
2925
+ *
2926
+ * // With working directory
2927
+ * await sandbox.runCommand('npm install', { cwd: '/app' })
2928
+ *
2929
+ * // Background with env vars
2930
+ * await sandbox.runCommand('node server.js', {
2931
+ * background: true,
2932
+ * env: { PORT: '3000' }
2933
+ * })
2934
+ * ```
2902
2935
  */
2903
- runCommand(commandOrArray: string | [string, ...string[]], argsOrOptions?: string[] | {
2904
- background?: boolean;
2905
- cwd?: string;
2906
- }, maybeOptions?: {
2936
+ runCommand(command: string, options?: {
2907
2937
  background?: boolean;
2908
2938
  cwd?: string;
2939
+ env?: Record<string, string>;
2909
2940
  }): Promise<{
2910
2941
  stdout: string;
2911
2942
  stderr: string;
package/dist/index.d.ts CHANGED
@@ -132,8 +132,13 @@ interface Sandbox$1 {
132
132
  readonly provider: string;
133
133
  /** Execute code in the sandbox */
134
134
  runCode(code: string, runtime?: Runtime): Promise<CodeResult$1>;
135
- /** Execute shell commands */
136
- runCommand(commandOrArray: string | [string, ...string[]], argsOrOptions?: string[] | RunCommandOptions, maybeOptions?: RunCommandOptions): Promise<CommandResult$1>;
135
+ /**
136
+ * Execute shell command
137
+ *
138
+ * Send raw command string to the sandbox - no preprocessing.
139
+ * The provider/server handles shell invocation and execution details.
140
+ */
141
+ runCommand(command: string, options?: RunCommandOptions): Promise<CommandResult$1>;
137
142
  /** Get information about the sandbox */
138
143
  getInfo(): Promise<SandboxInfo$1>;
139
144
  /** Get URL for accessing the sandbox on a specific port */
@@ -1695,6 +1700,10 @@ interface CommandRunOptions {
1695
1700
  shell?: string;
1696
1701
  /** Run in background (optional) */
1697
1702
  background?: boolean;
1703
+ /** Working directory for the command (optional) */
1704
+ cwd?: string;
1705
+ /** Environment variables (optional) */
1706
+ env?: Record<string, string>;
1698
1707
  }
1699
1708
  /**
1700
1709
  * Run - Resource namespace for executing code and commands
@@ -1740,6 +1749,8 @@ declare class Run {
1740
1749
  * @param options - Execution options
1741
1750
  * @param options.shell - Shell to use (optional)
1742
1751
  * @param options.background - Run in background (optional)
1752
+ * @param options.cwd - Working directory for the command (optional)
1753
+ * @param options.env - Environment variables (optional)
1743
1754
  * @returns Command execution result with stdout, stderr, exit code, and duration
1744
1755
  */
1745
1756
  command(command: string, options?: CommandRunOptions): Promise<CommandResult>;
@@ -2598,12 +2609,14 @@ declare class Sandbox {
2598
2609
  */
2599
2610
  runCodeRequest(code: string, language?: string): Promise<CodeExecutionResponse>;
2600
2611
  /**
2601
- * Execute a shell command (POST /run/command)
2612
+ * Execute a command and get the result
2613
+ * Lower-level method that returns the raw API response
2602
2614
  *
2603
- * @param options - Command options
2604
- * @param options.command - The command to execute
2615
+ * @param options.command - Command to execute
2605
2616
  * @param options.shell - Shell to use (optional)
2606
2617
  * @param options.background - Run in background (optional)
2618
+ * @param options.cwd - Working directory for the command (optional)
2619
+ * @param options.env - Environment variables (optional)
2607
2620
  * @returns Command execution result
2608
2621
  *
2609
2622
  * @example
@@ -2616,6 +2629,8 @@ declare class Sandbox {
2616
2629
  command: string;
2617
2630
  shell?: string;
2618
2631
  background?: boolean;
2632
+ cwd?: string;
2633
+ env?: Record<string, string>;
2619
2634
  }): Promise<RunCommandResponse>;
2620
2635
  /**
2621
2636
  * List files at the specified path
@@ -2891,21 +2906,37 @@ declare class Sandbox {
2891
2906
  language: string;
2892
2907
  }>;
2893
2908
  /**
2894
- * Execute shell command in the sandbox (convenience method)
2909
+ * Execute shell command in the sandbox
2895
2910
  *
2896
- * Delegates to sandbox.run.command() - prefer using that directly for new code.
2911
+ * Sends clean command string to server - no preprocessing or shell wrapping.
2912
+ * The server handles shell invocation, working directory, and backgrounding.
2897
2913
  *
2898
- * @param command - The command to execute (string or array form)
2899
- * @param argsOrOptions - Arguments array or options object
2900
- * @param maybeOptions - Options when using (command, args, options) form
2914
+ * @param command - The command to execute (raw string, e.g., "npm install")
2915
+ * @param options - Execution options
2916
+ * @param options.background - Run in background (server uses goroutines)
2917
+ * @param options.cwd - Working directory (server uses cmd.Dir)
2918
+ * @param options.env - Environment variables (server uses cmd.Env)
2901
2919
  * @returns Command execution result
2920
+ *
2921
+ * @example
2922
+ * ```typescript
2923
+ * // Simple command
2924
+ * await sandbox.runCommand('ls -la')
2925
+ *
2926
+ * // With working directory
2927
+ * await sandbox.runCommand('npm install', { cwd: '/app' })
2928
+ *
2929
+ * // Background with env vars
2930
+ * await sandbox.runCommand('node server.js', {
2931
+ * background: true,
2932
+ * env: { PORT: '3000' }
2933
+ * })
2934
+ * ```
2902
2935
  */
2903
- runCommand(commandOrArray: string | [string, ...string[]], argsOrOptions?: string[] | {
2904
- background?: boolean;
2905
- cwd?: string;
2906
- }, maybeOptions?: {
2936
+ runCommand(command: string, options?: {
2907
2937
  background?: boolean;
2908
2938
  cwd?: string;
2939
+ env?: Record<string, string>;
2909
2940
  }): Promise<{
2910
2941
  stdout: string;
2911
2942
  stderr: string;
package/dist/index.js CHANGED
@@ -728,7 +728,7 @@ var TerminalCommand = class {
728
728
  */
729
729
  async run(command, options) {
730
730
  const response = await this.runHandler(command, options?.background);
731
- const cmd2 = new Command({
731
+ const cmd = new Command({
732
732
  cmdId: response.data.cmd_id || "",
733
733
  terminalId: this.terminalId,
734
734
  command: response.data.command,
@@ -739,9 +739,9 @@ var TerminalCommand = class {
739
739
  durationMs: response.data.duration_ms,
740
740
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
741
741
  });
742
- cmd2.setWaitHandler((timeout) => this.waitHandler(cmd2.id, timeout));
743
- cmd2.setRetrieveHandler(() => this.retrieveHandler(cmd2.id));
744
- return cmd2;
742
+ cmd.setWaitHandler((timeout) => this.waitHandler(cmd.id, timeout));
743
+ cmd.setRetrieveHandler(() => this.retrieveHandler(cmd.id));
744
+ return cmd;
745
745
  }
746
746
  /**
747
747
  * List all commands executed in this terminal
@@ -750,7 +750,7 @@ var TerminalCommand = class {
750
750
  async list() {
751
751
  const response = await this.listHandler();
752
752
  return response.data.commands.map((item) => {
753
- const cmd2 = new Command({
753
+ const cmd = new Command({
754
754
  cmdId: item.cmd_id,
755
755
  terminalId: this.terminalId,
756
756
  command: item.command,
@@ -764,9 +764,9 @@ var TerminalCommand = class {
764
764
  startedAt: item.started_at,
765
765
  finishedAt: item.finished_at
766
766
  });
767
- cmd2.setWaitHandler((timeout) => this.waitHandler(cmd2.id, timeout));
768
- cmd2.setRetrieveHandler(() => this.retrieveHandler(cmd2.id));
769
- return cmd2;
767
+ cmd.setWaitHandler((timeout) => this.waitHandler(cmd.id, timeout));
768
+ cmd.setRetrieveHandler(() => this.retrieveHandler(cmd.id));
769
+ return cmd;
770
770
  });
771
771
  }
772
772
  /**
@@ -776,7 +776,7 @@ var TerminalCommand = class {
776
776
  */
777
777
  async retrieve(cmdId) {
778
778
  const response = await this.retrieveHandler(cmdId);
779
- const cmd2 = new Command({
779
+ const cmd = new Command({
780
780
  cmdId: response.data.cmd_id,
781
781
  terminalId: this.terminalId,
782
782
  command: response.data.command,
@@ -788,9 +788,9 @@ var TerminalCommand = class {
788
788
  startedAt: response.data.started_at,
789
789
  finishedAt: response.data.finished_at
790
790
  });
791
- cmd2.setWaitHandler((timeout) => this.waitHandler(cmd2.id, timeout));
792
- cmd2.setRetrieveHandler(() => this.retrieveHandler(cmd2.id));
793
- return cmd2;
791
+ cmd.setWaitHandler((timeout) => this.waitHandler(cmd.id, timeout));
792
+ cmd.setRetrieveHandler(() => this.retrieveHandler(cmd.id));
793
+ return cmd;
794
794
  }
795
795
  };
796
796
 
@@ -1810,6 +1810,8 @@ var Run = class {
1810
1810
  * @param options - Execution options
1811
1811
  * @param options.shell - Shell to use (optional)
1812
1812
  * @param options.background - Run in background (optional)
1813
+ * @param options.cwd - Working directory for the command (optional)
1814
+ * @param options.env - Environment variables (optional)
1813
1815
  * @returns Command execution result with stdout, stderr, exit code, and duration
1814
1816
  */
1815
1817
  async command(command, options) {
@@ -1935,7 +1937,7 @@ var Sandbox = class {
1935
1937
  await this.writeFile(path, content);
1936
1938
  },
1937
1939
  mkdir: async (path) => {
1938
- await this.runCommand((0, import_cmd.mkdir)(path));
1940
+ await this.runCommand((0, import_cmd.escapeArgs)((0, import_cmd.mkdir)(path)));
1939
1941
  },
1940
1942
  readdir: async (path) => {
1941
1943
  const response = await this.listFiles(path);
@@ -1947,7 +1949,7 @@ var Sandbox = class {
1947
1949
  }));
1948
1950
  },
1949
1951
  exists: async (path) => {
1950
- const result = await this.runCommand(import_cmd.test.exists(path));
1952
+ const result = await this.runCommand((0, import_cmd.escapeArgs)(import_cmd.test.exists(path)));
1951
1953
  return result.exitCode === 0;
1952
1954
  },
1953
1955
  remove: async (path) => {
@@ -1972,7 +1974,13 @@ var Sandbox = class {
1972
1974
  };
1973
1975
  },
1974
1976
  command: async (command, options) => {
1975
- const result = await this.runCommandRequest({ command, shell: options?.shell, background: options?.background });
1977
+ const result = await this.runCommandRequest({
1978
+ command,
1979
+ shell: options?.shell,
1980
+ background: options?.background,
1981
+ cwd: options?.cwd,
1982
+ env: options?.env
1983
+ });
1976
1984
  return {
1977
1985
  stdout: result.data.stdout,
1978
1986
  stderr: result.data.stderr,
@@ -2286,12 +2294,14 @@ API request failed (${response.status}): ${error}`
2286
2294
  });
2287
2295
  }
2288
2296
  /**
2289
- * Execute a shell command (POST /run/command)
2297
+ * Execute a command and get the result
2298
+ * Lower-level method that returns the raw API response
2290
2299
  *
2291
- * @param options - Command options
2292
- * @param options.command - The command to execute
2300
+ * @param options.command - Command to execute
2293
2301
  * @param options.shell - Shell to use (optional)
2294
2302
  * @param options.background - Run in background (optional)
2303
+ * @param options.cwd - Working directory for the command (optional)
2304
+ * @param options.env - Environment variables (optional)
2295
2305
  * @returns Command execution result
2296
2306
  *
2297
2307
  * @example
@@ -2888,29 +2898,35 @@ API request failed (${response.status}): ${error}`
2888
2898
  return this.run.code(code, language ? { language } : void 0);
2889
2899
  }
2890
2900
  /**
2891
- * Execute shell command in the sandbox (convenience method)
2901
+ * Execute shell command in the sandbox
2892
2902
  *
2893
- * Delegates to sandbox.run.command() - prefer using that directly for new code.
2903
+ * Sends clean command string to server - no preprocessing or shell wrapping.
2904
+ * The server handles shell invocation, working directory, and backgrounding.
2894
2905
  *
2895
- * @param command - The command to execute (string or array form)
2896
- * @param argsOrOptions - Arguments array or options object
2897
- * @param maybeOptions - Options when using (command, args, options) form
2906
+ * @param command - The command to execute (raw string, e.g., "npm install")
2907
+ * @param options - Execution options
2908
+ * @param options.background - Run in background (server uses goroutines)
2909
+ * @param options.cwd - Working directory (server uses cmd.Dir)
2910
+ * @param options.env - Environment variables (server uses cmd.Env)
2898
2911
  * @returns Command execution result
2912
+ *
2913
+ * @example
2914
+ * ```typescript
2915
+ * // Simple command
2916
+ * await sandbox.runCommand('ls -la')
2917
+ *
2918
+ * // With working directory
2919
+ * await sandbox.runCommand('npm install', { cwd: '/app' })
2920
+ *
2921
+ * // Background with env vars
2922
+ * await sandbox.runCommand('node server.js', {
2923
+ * background: true,
2924
+ * env: { PORT: '3000' }
2925
+ * })
2926
+ * ```
2899
2927
  */
2900
- async runCommand(commandOrArray, argsOrOptions, maybeOptions) {
2901
- let commandParts;
2902
- let options;
2903
- if (Array.isArray(commandOrArray)) {
2904
- commandParts = commandOrArray;
2905
- options = argsOrOptions;
2906
- } else {
2907
- const args = Array.isArray(argsOrOptions) ? argsOrOptions : [];
2908
- commandParts = [commandOrArray, ...args];
2909
- options = Array.isArray(argsOrOptions) ? maybeOptions : argsOrOptions;
2910
- }
2911
- const finalCommand = (0, import_cmd.cmd)(commandParts, options);
2912
- const fullCommand = (0, import_cmd.escapeArgs)(finalCommand);
2913
- return this.run.command(fullCommand, { background: options?.background });
2928
+ async runCommand(command, options) {
2929
+ return this.run.command(command, options);
2914
2930
  }
2915
2931
  /**
2916
2932
  * Get server information