vercel/ai · error
Sandbox session is not available
Error message
Sandbox session is not available
What it means
Identical to the bash_20241022 variant: the bash_20250124 tool's execute callback throws 'Sandbox session is not available' when no `experimental_sandbox` session is present in the tool-call options. Commands can only be executed through a sandbox.
Source
Thrown at packages/anthropic/src/tool/bash_20250124.ts:87
export function bash_20250124<OUTPUT>(
options: Omit<Bash20250124Options<OUTPUT>, 'execute'> & {
execute: Bash20250124Options<OUTPUT>['execute'];
},
): ProviderDefinedTool<Bash20250124Input, OUTPUT, {}>;
export function bash_20250124<OUTPUT>(
options: Bash20250124OptionsWithNullableExecute<OUTPUT> = {},
): ProviderDefinedTool<Bash20250124Input, OUTPUT, {}> {
const { execute, ...rest } = options;
if (execute === undefined) {
return bash_20250124_internal({
...rest,
execute: async (
{ command },
{ abortSignal, experimental_sandbox: sandbox },
) => {
if (!sandbox) {
throw new Error('Sandbox session is not available');
}
return await sandbox.run({
command,
abortSignal,
});
},
} as Bash20250124Options<Bash20250124DefaultOutput>) as ReturnType<
typeof bash_20250124_internal<OUTPUT>
>;
}
return bash_20250124_internal({
...rest,
...(execute === null ? {} : { execute }),
} as Bash20250124Options<OUTPUT>);
}
View on GitHub (pinned to 69428b1f8b)
Solutions
- Pass an `experimental_sandbox` session (e.g. from @ai-sdk/sandbox or a custom implementation) in the tool execution options.
- Remove the bash tool if your runtime cannot supply a sandbox, replacing it with a controlled custom tool.
- Ensure the sandbox session is created before the agent loop executes tool calls.
Example fix
// before
steps: tools: { bash: bash_20250124({ ... }) } // executed without sandbox
// after
const sandbox = await createSandbox();
await generateText({
tools: { bash: bash_20250124({ ... }) },
experimental_context: { experimental_sandbox: sandbox },
}); Defensive patterns
Strategy: validation
Validate before calling
if (!sandboxSession) {
throw new Error('bash_20250124 tool requires an experimental_sandbox session');
}
// configure the sandbox before starting generateText/streamText Type guard
function hasSandbox(opts: any): opts is { experimental_sandbox: { run: (args: { command: string }) => Promise<unknown> } } {
return !!opts?.experimental_sandbox && typeof opts.experimental_sandbox.run === 'function';
} Try / catch
try {
return await sandbox.run({ command, abortSignal });
} catch (error) {
if (error instanceof Error && error.message === 'Sandbox session is not available') {
return { type: 'error', error: 'Initialize an experimental_sandbox session to use the bash_20250124 tool.' };
}
throw error;
} Prevention
- Wire sandbox creation into agent setup whenever bash tool versions are enabled.
- Fail fast with a startup config check rather than at first tool call.
- Keep sandbox setup shared between old and new bash tool versions to avoid migration gaps.
When it happens
Trigger: Using the anthropic bash_20250124 tool (via bashTool) in generateText/streamText where the call options lack experimental_sandbox.
Common situations: Migrating to the newer 20250124 bash tool version without also wiring sandbox configuration; running agents in environments with no sandbox provider installed.
Related errors
- Sandbox session is not available
- Invalid argument for parameter batch: batch must be a suppor
- error.message
- CODE_MODE_HOST_TOOL_ERROR
- CODE_MODE_TOOL_ERROR
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/968764d16221310c.
Report an issue: GitHub.