@runloop/api-client - v1.18.0
    Preparing search index...

    Object-oriented interface for working with Devboxes.

    The Devbox class provides a high-level, object-oriented API for managing devboxes. Devboxes are containers that run your code in a consistent environment. They have the the following categories of operations:

    • net - Network operations
    • cmd - Command execution operations
    • file - File operations
    import { RunloopSDK } from '@runloop/api-client-ts';

    const runloop = new RunloopSDK();
    const devbox = await runloop.devbox.create({ name: 'my-devbox' });
    devbox.cmd.exec('echo "Hello, World!"');
    ...
    Index

    Properties

    Network operations on the devbox.

    Command execution operations on the devbox.

    File operations on the devbox.

    Accessors

    Methods

    • Create a named shell instance for stateful command execution.

      Named shells are stateful and maintain environment variables and the current working directory (CWD) across commands, just like a real shell on your local computer. Commands executed through the same named shell instance will execute sequentially - the shell can only run one command at a time with automatic queuing. This ensures that environment changes and directory changes from one command are preserved for the next command.

      Parameters

      • OptionalshellName: string = ...

        The name of the persistent shell session. If not provided, a UUID will be generated automatically.

      Returns DevboxNamedShell

      A DevboxNamedShell instance for executing commands in the named shell

      // Create a named shell with a custom name
      const shell = devbox.shell('my-session');

      // Create a named shell with an auto-generated UUID name
      const shell2 = devbox.shell();

      // Commands execute sequentially and share state
      await shell.exec('cd /app');
      await shell.exec('export MY_VAR=value');
      await shell.exec('echo $MY_VAR'); // Will output 'value' because env is preserved
      await shell.exec('pwd'); // Will output '/app' because CWD is preserved
    • Get the complete devbox data from the API.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<DevboxView>

      The devbox data

      const info = await devbox.getInfo();
      console.log(`Devbox name: ${info.name}, status: ${info.status}`);
    • Get the tunnel information for this devbox. Returns null if no tunnel has been enabled.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<TunnelView | null>

      The tunnel information, or null if no tunnel exists

      const tunnel = await devbox.getTunnel();
      if (tunnel) {
      console.log(`Tunnel key: ${tunnel.tunnel_key}`);
      }
    • Get the tunnel URL for a specific port. Throws an error if no tunnel has been enabled.

      Parameters

      • port: number

        The port number to construct the URL for

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<string>

      The tunnel URL for the specified port

      const url = await devbox.getTunnelUrl(8080);
      console.log(`Access your app at: ${url}`);
      // Output: https://8080-abc123xyz.tunnel.runloop.ai

      If no tunnel has been enabled for this devbox

    • Get all logs from a running or completed devbox. Optionally filter by execution ID or shell name.

      Parameters

      • Optionalparams: LogListParams

        Optional filter parameters (execution_id, shell_name)

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<DevboxLogsListView>

      The devbox logs

      const logs = await devbox.logs();
      for (const log of logs.logs) {
      console.log(`[${log.level}] ${log.message}`);
      }

      // Filter by execution ID
      const execLogs = await devbox.logs({ execution_id: 'exec-123' });

      // Filter by shell name
      const shellLogs = await devbox.logs({ shell_name: 'my-shell' });
    • Wait for the devbox to reach the running state. Uses optimized server-side polling for better performance.

      Parameters

      Returns Promise<DevboxView>

      The devbox data when running state is reached

      const devbox = Devbox.fromId(runloop, 'devbox-123');
      await devbox.awaitRunning();
      console.log('Devbox is now running');
    • Wait for the devbox to reach the suspended state. Uses optimized server-side polling for better performance.

      Parameters

      Returns Promise<DevboxView>

      The devbox data when suspended state is reached

      await devbox.suspend();
      await devbox.awaitSuspended();
      console.log('Devbox is now suspended');
    • Create a disk snapshot of the devbox. Returns a snapshot that is completed. If you don't want to block on completion, use snapshotDiskAsync().

      Parameters

      • Optionalparams: DevboxSnapshotDiskParams

        Snapshot creation parameters

      • Optionaloptions: RequestOptions<unknown> & {
            polling?: Partial<PollingOptions<DevboxSnapshotView>>;
        }

        Request options with optional polling configuration

      Returns Promise<RunloopSDK.Snapshot>

      A completed Snapshot instance

      const snapshot = await devbox.snapshotDisk({ name: 'pre-deployment' });
      console.log(`Snapshot ${snapshot.id} created successfully`);
    • Create a disk snapshot of the devbox asynchronously. Returns a snapshot that is not yet completed but has started. You can await completion using snapshot.awaitCompleted().

      Parameters

      • Optionalparams: DevboxSnapshotDiskParams

        Snapshot creation parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<RunloopSDK.Snapshot>

      A Snapshot instance that has started but may not be completed

      const snapshot = await devbox.snapshotDiskAsync({ name: 'backup' });
      // Do other work...
      await snapshot.awaitCompleted();
    • Shutdown the devbox.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<DevboxView>

      Shutdown result

      await devbox.shutdown();
      
    • Suspend the devbox and create a disk snapshot.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<DevboxView>

      Suspend result

      await devbox.suspend();
      // Optionally, wait for the devbox to reach the suspended state
      await devbox.awaitSuspended();
    • Resume a suspended devbox without waiting for it to reach the running state.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<DevboxView>

      Resume result

      await devbox.resumeAsync();
      // Optionally wait for running state
      await devbox.awaitRunning();
    • Send a keep-alive signal to prevent idle shutdown.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<unknown>

      Keep-alive result

      // Send keep-alive periodically
      setInterval(() => devbox.keepAlive(), 60000);