`Experimental_SandboxSession`

Experimental_SandboxSession

Experimental_SandboxSession 인터페이스는 tools가 명령을 실행하는 데 사용할 수 있는 실행 환경을 설명해요. generateText, streamText, ToolLoopAgent.generate, ToolLoopAgent.stream, 에이전트 UI 스트림 헬퍼에 experimental_sandbox 옵션으로 실험적 sandbox를 전달해 tool 설명 함수와 tool 실행에서 사용할 수 있게 하세요.

이 API는 실험적이며 패치 릴리스에서 변경될 수 있어요. 실험적 sandbox를 전달한다고 해서 tool 자체가 sandbox 처리되지는 않아요. tool 코드는 tool이 명시적으로 작업을 실험적 sandbox에 위임하지 않는 한 여전히 애플리케이션 프로세스에서 실행돼요.

출처: 문서

본문

Import

<Snippet text={import type { Experimental_SandboxSession } from "ai"} prompt={false} />

타입 정의 (Type Definition)

type Experimental_SandboxSession = {
  readonly description: string;
  readonly run: (options: {
    command: string;
    workingDirectory?: string;
    env?: Record<string, string>;
    abortSignal?: AbortSignal;
  }) => PromiseLike<{
    exitCode: number;
    stdout: string;
    stderr: string;
  }>;
};

속성 (Properties)

<PropertiesTable content={[ { name: 'description', type: 'string', description: 'Description of the experimental sandbox environment. Include this in your prompt or instructions when the model needs to know details such as the root directory, exposed ports, public hostname, or other environment constraints. The AI SDK does not add it to the prompt automatically.', }, { name: 'run', type: '(options: { command: string; workingDirectory?: string; env?: Record<string, string>; abortSignal?: AbortSignal }) => PromiseLike<{ exitCode: number; stdout: string; stderr: string }>', description: 'Executes a command in the experimental sandbox and resolves with the command exit code, standard output, and standard error.', properties: [ { type: 'options', parameters: [ { name: 'command', type: 'string', description: 'The command to execute in the experimental sandbox.', }, { name: 'workingDirectory', type: 'string | undefined', description: 'Optional working directory to execute the command in. If omitted, the experimental sandbox implementation uses its default working directory.', }, { name: 'env', type: 'Record<string, string> | undefined', description: 'Optional environment variables to set for the command. Merged with the experimental sandbox default environment, with these values taking precedence. Passing secrets here instead of inlining them into the command avoids leaking them in logs. Implementations that cannot set environment variables reject this option.', }, { name: 'abortSignal', type: 'AbortSignal | undefined', description: 'Optional abort signal that the experimental sandbox implementation can use to cancel the command.', }, ], }, ], }, ]} />

예제 (Example)

const result = await generateText({
  model: __MODEL__,
  tools: { shell },
  experimental_sandbox,
  prompt: 'Run the test suite.',
});

tool 안에서는 두 번째 execute 인자에서 실험적 sandbox를 읽으세요:

const shell = tool({
  inputSchema: z.object({
    command: z.string(),
    workingDirectory: z.string().optional(),
  }),
  execute: async (
    { command, workingDirectory },
    { abortSignal, experimental_sandbox },
  ) => {
    if (!experimental_sandbox) {
      throw new Error('Experimental sandbox is not available');
    }

    return experimental_sandbox.run({
      command,
      workingDirectory,
      abortSignal,
    });
  },
});

함께 보기 (See Also)

더 알아보기 (Learn more)

전체 사이트맵