Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🥾 fix: Define Code Execution Persistence Boundaries (#16099)
Danny Avila864c68edfcb9
diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.jsonindex c13e2bca02..d9b68ad1e6 100644--- a/client/src/locales/en/translation.json+++ b/client/src/locales/en/translation.json@@ -697,7 +697,7 @@"com_nav_info_save_draft": "When enabled, the text and attachments you enter in the chat form will be automatically saved locally as drafts. These drafts will be available even if you reload the page or switch to a different conversation. Drafts are stored locally on your device and are deleted once the message is sent.","com_nav_info_show_thinking": "When enabled, the chat will display the thinking dropdowns open by default, allowing you to view the AI's reasoning in real-time. When disabled, the thinking dropdowns will remain closed by default for a cleaner and more streamlined interface","com_nav_info_smooth_streaming": "When enabled, newly streamed words fade in smoothly for the latest response. This is purely visual — it does not delay token delivery — and is disabled automatically when your device prefers reduced motion.",- "com_nav_info_stateful_sessions": "When enabled, this agent uses the dedicated stateful Code API instead of the default stateless service. Files, installed packages, and working state usually carry over between runs. The workspace may occasionally reset, so save anything important under /mnt/data. Requires Code Interpreter and the app-level stateful sessions capability.",+ "com_nav_info_stateful_sessions": "When enabled, this agent uses the dedicated stateful Code API instead of the default stateless service. Retained files under /mnt/data carry across runs, but each run starts a fresh process. Shell variables, the working directory, $HOME, temporary files, global installs, and background processes are not durable. The runtime may reset, so keep anything important under /mnt/data. Requires Code Interpreter and the app-level stateful sessions capability.","com_nav_info_stateful_code_environment": "Choose who shares this agent's stateful workspace. This does not share live files with stateless code sessions.","com_nav_info_tool_background": "When enabled, the model can run this tool in the background: the conversation continues immediately while the tool runs, and the model retrieves the result later with the background task tool. Requires the app-level background tools capability.","com_nav_info_user_name_display": "When enabled, the username of the sender will be shown above each message you send. When disabled, you will only see \"You\" above your messages.",diff --git a/packages/api/src/agents/__tests__/initialize.test.ts b/packages/api/src/agents/__tests__/initialize.test.tsindex 91764ea1ad..36fcc14add 100644--- a/packages/api/src/agents/__tests__/initialize.test.ts+++ b/packages/api/src/agents/__tests__/initialize.test.ts@@ -2614,7 +2614,7 @@ describe('initializeAgent — execute_code capability expansion', () => {but never appears in the tool definitions the LLM sees. */expect(names).not.toContain('execute_code');const readFile = result.toolDefinitions?.find((d) => d.name === 'read_file');- expect(readFile?.description).toContain('code-execution sandbox');+ expect(readFile?.description).toContain('code-sandbox');expect(readFile?.description).not.toContain('{skillName}');expect(readFile?.description).not.toContain('SKILL.md');const createFile = result.toolDefinitions?.find((d) => d.name === 'create_file');diff --git a/packages/api/src/agents/tools.spec.ts b/packages/api/src/agents/tools.spec.tsindex d21683a668..96bfa32cdb 100644--- a/packages/api/src/agents/tools.spec.ts+++ b/packages/api/src/agents/tools.spec.ts@@ -494,13 +494,17 @@ describe('registerCodeExecutionTools', () => {});const readFile = result.toolDefinitions.find((d) => d.name === 'read_file');- expect(readFile?.description).toContain('code-execution sandbox');+ expect(readFile?.description).toContain('code-sandbox');expect(readFile?.description).toContain('/mnt/data/');expect(readFile?.description).toContain('Do not run ls/find');- expect(readFile?.description).toContain('/tmp is per-call scratch');- expect(readFile?.description).toContain('truncate around 256KB');- expect(readFile?.description).toContain('images (png, jpeg, gif, webp)');- expect(readFile?.description).toContain('true filesystem discovery');+ expect(readFile?.description).toContain('only retained files under /mnt/data');+ expect(readFile?.description).toContain('$HOME');+ expect(readFile?.description).toContain('/tmp');+ expect(readFile?.description).toContain('global installs');+ expect(readFile?.description).toContain('background processes are call-local');+ expect(readFile?.description).toContain('truncates around 256KB');+ expect(readFile?.description).toContain('png, jpeg, gif, and webp images');+ expect(readFile?.description).toContain('filesystem discovery');expect(readFile?.description).not.toContain('{skillName}');expect(readFile?.description).not.toContain('SKILL.md');expect(JSON.stringify(readFile?.parameters)).not.toContain('{skillName}');@@ -526,6 +530,10 @@ describe('registerCodeExecutionTools', () => {);expect(readFile?.description).toContain('workspace/');expect(readFile?.description).toContain('attached');+ expect(readFile?.description).toContain(+ 'Only the registered workspace persists for attached commands',+ );+ expect(readFile?.description).toContain('operator-managed');expect(readFile?.parameters).toMatchObject({properties: {start_line: { type: 'integer' },@@ -701,11 +709,21 @@ describe('registerCodeExecutionTools', () => {includeSkillFileInstructions: false,enableToolOutputReferences: false,});+ const attachedWithoutRefs = registerCodeExecutionTools({+ toolRegistry: makeRegistry(),+ toolDefinitions: [],+ includeBash: true,+ includeSkillFileInstructions: false,+ enableToolOutputReferences: false,+ workspaceTools: true,+ workspaceOperations: new Set(CODE_WORKSPACE_OPERATIONS),+ });expect(maxToolDescriptionLength([...skillAwareWithRefs.toolDefinitions,...codeOnlyWithoutRefs.toolDefinitions,+ ...attachedWithoutRefs.toolDefinitions,]),).toBeLessThanOrEqual(TOOL_DESCRIPTION_ADVISORY_MAX_LENGTH);});diff --git a/packages/api/src/agents/tools.ts b/packages/api/src/agents/tools.tsindex 08f4091d29..3b4827eae7 100644--- a/packages/api/src/agents/tools.ts+++ b/packages/api/src/agents/tools.ts@@ -478,11 +478,13 @@ const READ_FILE_DEF: LCTool = Object.freeze({responseFormat: ReadFileToolDefinition.responseFormat,}) as LCTool;-const CODE_READ_FILE_DESCRIPTION = `Read a known file from the code-execution sandbox. Text files return line-numbered content (large files truncate around 256KB); images (png, jpeg, gif, webp) return as visual content you can see.+const CODE_READ_FILE_DESCRIPTION = `Read a known code-sandbox file. Text is line-numbered and truncates around 256KB; png, jpeg, gif, and webp images return as visual content.-Use for text, CSV, JSON, Markdown, logs, small source files, and images at paths returned by tool output, just written, or under /mnt/data/. Do not run ls/find just to rediscover known paths. Use bash_tool for other binary files, large files, transforms, metadata, or true filesystem discovery. /tmp is per-call scratch and unavailable later.`;+Use paths returned by tool output, just written, or under /mnt/data/. Do not run ls/find to rediscover known paths. Use bash_tool for binary or large files, transforms, metadata, and filesystem discovery.-const ATTACHED_WORKSPACE_READ_FILE_INSTRUCTIONS = `For an attached environment, use "workspace/{relativePath}" to read a file from the workspace directory registered on the worker. Use a canonical relative path without empty, ".", or ".." segments. It may be an existing project, a Git repository, or an empty directory; Git is not required. The worker's host path stays private. Use start_line and max_lines for bounded pagination.`;+For managed execution, only retained files under /mnt/data reach later calls. $HOME, /tmp, $TMPDIR, shell/environment state, cwd, global installs, and background processes are call-local.`;++const ATTACHED_WORKSPACE_READ_FILE_INSTRUCTIONS = `For an attached environment, read registered files as "workspace/{relativePath}". Use a canonical relative path without empty, ".", or ".." segments; the worker's host path stays private. Only the registered workspace persists for attached commands. Project dependencies stored there persist, while $HOME and global/system packages are operator-managed. Use start_line and max_lines for bounded pagination.`;const CODE_READ_FILE_PARAMETERS: LCTool['parameters'] = Object.freeze({type: 'object',diff --git a/packages/api/src/code/command.spec.ts b/packages/api/src/code/command.spec.tsindex 583990bd66..eb0eb7931f 100644--- a/packages/api/src/code/command.spec.ts+++ b/packages/api/src/code/command.spec.ts@@ -3,6 +3,7 @@ import { createServer } from 'node:http';import type { AddressInfo } from 'node:net';import type { CodeBridgeFetch } from './bridge';import {+ ATTACHED_WORKSPACE_BASH_DESCRIPTION,ATTACHED_WORKSPACE_BASH_SCHEMA,buildAttachedWorkspaceBashSchema,createAttachedWorkspaceBashTool,@@ -13,6 +14,31 @@ import {} from './command';import { BACKGROUND_TOOL_INVOCATION_CONFIG_KEY } from '~/agents/invocation';+describe('attached workspace Bash contract', () => {+ test('distinguishes durable workspace files from per-call and operator-managed state', () => {+ expect(ATTACHED_WORKSPACE_BASH_DESCRIPTION).toContain(+ 'Only registered-workspace files persist',+ );+ expect(ATTACHED_WORKSPACE_BASH_DESCRIPTION).toContain('Install project dependencies there');+ expect(ATTACHED_WORKSPACE_BASH_DESCRIPTION).toContain('$HOME');+ expect(ATTACHED_WORKSPACE_BASH_DESCRIPTION).toContain('/tmp, $TMPDIR');+ expect(ATTACHED_WORKSPACE_BASH_DESCRIPTION).toContain('global/system packages');+ expect(ATTACHED_WORKSPACE_BASH_DESCRIPTION).toContain('background processes do not survive');+ });++ test('keeps the command parameter persistence warning next to generated commands', () => {+ expect(ATTACHED_WORKSPACE_BASH_SCHEMA).toMatchObject({+ properties: {+ command: {+ description: expect.stringContaining(+ 'Only files written inside the workspace persist between calls',+ ),+ },+ },+ });+ });+});+describe('programmatic Bash Git identity', () => {test('applies authorship before the SDK sends a programmatic script', async () => {let receivedCode = '';diff --git a/packages/api/src/code/command.ts b/packages/api/src/code/command.tsindex 5d7a5ba0c4..f718a73c56 100644--- a/packages/api/src/code/command.ts+++ b/packages/api/src/code/command.ts@@ -25,14 +25,14 @@ import { BACKGROUND_TOOL_INVOCATION_CONFIG_KEY } from '~/agents/invocation';const DEFAULT_OUTPUT_BYTES = 256 * 1024;-export const ATTACHED_WORKSPACE_BASH_DESCRIPTION = `Runs bash commands inside the selected attached environment and returns stdout/stderr. The workspace may be an existing project, a Git repository, or an empty directory; Git is not required.+export const ATTACHED_WORKSPACE_BASH_DESCRIPTION = `Runs bash commands inside the selected attached environment and returns stdout/stderr. Its workspace may be an existing project, Git repository, or empty directory.Session behavior:-- This tool starts a new command. It does not inspect an existing background task. Use check_background_task with background_task_id when that tool is available to inspect an existing task; do not send a task ID to bash_tool.-- Files in the registered workspace persist between calls.-- Each call runs in a fresh sandboxed process; shell variables, the working directory, temporary files, and background processes do not survive the call.-- Network access follows the sandbox policy configured on the worker and may be unavailable.-- Commands and file access remain confined by the worker's runtime policy.+- This starts a new command, not an existing background task. Inspect a background_task_id with check_background_task when available; never send it to bash_tool.+- Only registered-workspace files persist between calls. Install project dependencies there.+- Every call is a fresh process. Shell and exported variables, cwd, /tmp, $TMPDIR, and background processes do not survive.+- $HOME, global/system packages, and machine services are operator-managed. Do not change or rely on them as session storage.+- Network access follows the sandbox policy configured on the worker and may be unavailable. File access follows the same worker policy.- Input code is already displayed to the user; do not repeat it unless asked.- Explicitly print every result the user should see.- Never use this tool to execute malicious commands.`;@@ -44,7 +44,7 @@ const attachedCommandSchema: NonNullable<LCTool['parameters']> = {...bashSchema.properties?.command,type: 'string',description:- 'The bash command or script to execute from the attached workspace root. Files written in the workspace persist between calls, but each call starts a fresh process.',+ 'The bash command or script to execute from the attached workspace root. Only files written inside the workspace persist between calls. Each call starts a fresh process; $HOME, temporary files, shell state, global installs, and background processes are not durable.',};/** `maxLength` is valid JSON Schema, but the SDK's schema type omits it. */