`Experimental_SandboxSession`
Experimental_SandboxSession
Experimental_SandboxSession 인터페이스는 tools가 명령을 실행하는 데 사용할 수 있는 실행 환경을 설명해요. generateText, streamText, ToolLoopAgent.generate, ToolLoopAgent.stream, 에이전트 UI 스트림 헬퍼에 experimental_sandbox 옵션으로 실험적 sandbox를 전달해 tool 설명 함수와 tool 실행에서 사용할 수 있게 하세요.
출처: 문서
본문
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)
- generateText
- streamText
- embed
- embedMany
- rerank
- generateImage
- experimental_streamTranscribe
- experimental_streamTranslate
- transcribe
- generateSpeech
- experimental_generateVideo
- experimental_evaluate
- uploadFile
- uploadSkill
- Agent (Interface)
- ToolLoopAgent
- createAgentUIStream
- createAgentUIStreamResponse
- pipeAgentUIStreamToResponse
- experimental_startBatch
- tool
- experimental_getBatchStatus
- dynamicTool
- experimental_getBatchResults
- experimental_cancelBatch
- createMCPClient
- experimental_getRealtimeToolDefinitions
- toolSearch
- experimental_listBatches
- MCP Apps
- Experimental_StdioMCPTransport
- jsonSchema
- zodSchema
- valibotSchema
- Output
- filterActiveTools
- ModelMessage
- UIMessage
- validateUIMessages
- safeValidateUIMessages
- Experimental_SandboxSession
- createProviderRegistry
- customProvider
- cosineSimilarity
- wrapLanguageModel
- wrapImageModel
- LanguageModelV4Middleware
- extractReasoningMiddleware
- simulateStreamingMiddleware
- defaultInstructionsMiddleware
- defaultSettingsMiddleware
- addToolInputExamplesMiddleware
- extractJsonMiddleware
- isStepCount
- hasToolCall
- isLoopFinished
- simulateReadableStream
- smoothStream
- generateId
- createIdGenerator
- DefaultGeneratedFile