Skip to content

🛻 feat: Route Bash Through Attached Workspaces - #15546

Merged
danny-avila merged 2 commits into
devfrom
danny-avila/code-workspace-command
Sep 4, 2026
Merged

danny-avila merged 2 commits into
devfrom
danny-avila/code-workspace-command

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

Summary

I routed the existing approval-gated bash_tool through the selected attached BYOM environment while preserving the managed Code API execution path. This depends on LibreChat #15527 and the Code Interpreter command stack #97–#101.

  • Select the attached worker command transport only when the resolved environment type is attached.
  • Preserve the existing bash_tool name and schema so hook-based tool approvals remain the single permission gate.
  • Validate command requests and untrusted worker results against the provider-neutral command protocol, including UTF-8 byte, timeout, output, exit-code, and signal limits.
  • Preserve positional argument semantics using shell-safe quoting without interpolating argument content.
  • Describe persistent workspace files, fresh per-call processes, optional repositories, and worker-controlled network policy accurately to the model.
  • Allow command HTTP deadlines to include bounded transport grace beyond the requested sandbox timeout.
  • Cover attached routing, authentication, result formatting, output bounds, cancellation-compatible transport, and empty-directory behavior.

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • Ran jest --runInBand --coverage=false src/code/command.spec.ts src/code/workspace.spec.ts src/agents/tools.spec.ts src/agents/handlers.spec.ts from packages/api: 233 tests passed.
  • Ran the package API production build with declaration generation.
  • Ran ESLint with zero warnings on every changed implementation and test file.
  • Live attached-worker verification will be recorded against the matching Code Interpreter command stack before merge.

Test Configuration:

  • macOS
  • Node.js 24.16.0
  • npm 11.13.0
  • Attached workspace ID: primary

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • Any changes dependent on mine have been merged and published in downstream modules.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

Live BYOM verification completed against Code Interpreter #101 exact head 2c7ba7f:

  • Ran Code API on 23113 with Redis on 26380 and an outbound-only librechat-code worker using native SRT.
  • Registered a new empty non-Git directory as workspace primary.
  • Invoked the compiled LibreChat createAttachedWorkspaceBashTool adapter through /v1/workspace-tools/execute.
  • Confirmed a file written by one command remained available to a later command.
  • Confirmed an argument containing ; touch escaped.txt remained positional data and did not create the file.
  • Confirmed the sandbox could not read /Users/danny/.ssh/id_rsa.
  • Confirmed a request to the host Code API loopback port was blocked (curl exit 7).

Focused package tests remain 233/233 passing, package declaration build passes, and changed-file ESLint passes.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review commit 50c075e

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-04T04:02:23.744399Z a44729f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review commit 4399b7c (supersedes the earlier head after the lower formatting-only restack)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 4399b7c621

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head 9155a49

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 9155a49b52

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila changed the title 🧭 feat(code): Route Bash Through Attached Workspaces 🎒 feat(code): Run Bash in Attached Workspaces Sep 3, 2026
Copilot AI lite review requested due to automatic review settings September 4, 2026 03:57
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head a44729f. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: a44729f16f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Adds support for running the existing approval-gated bash_tool through an attached workspace (“BYOM” worker) transport while keeping the managed Code API execution path intact.

Changes:

  • Extends the workspace tool protocol to include an execute_command operation with request/result validation and bounded timeouts/output.
  • Introduces an attached-workspace-backed bash tool implementation and exports it from the API package.
  • Routes bash_tool to the attached transport when environmentType === 'attached', and updates tool definitions/tests accordingly.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/api/src/code/workspace.ts Adds execute_command request/result types, protocol validation, and adjusted timeout behavior with a transport grace period
packages/api/src/code/workspace.spec.ts Adds tests for valid/invalid execute_command requests/results
packages/api/src/code/index.ts Exports the new command module
packages/api/src/code/command.ts Implements the attached-workspace bash tool wrapper and command argument quoting/formatting
packages/api/src/code/command.spec.ts Tests attached-workspace bash tool behavior (auth headers, quoting, formatting)
packages/api/src/agents/tools.ts Switches bash tool description/schema when workspace tools are enabled
packages/api/src/agents/tools.spec.ts Updates mocks/assertions for the new attached bash definition behavior
api/server/services/tests/ToolService.spec.js Verifies ToolService loads the attached bash tool for attached environments
api/server/services/ToolService.js Routes bash tool creation via createAttachedWorkspaceBashTool when attached

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +349 to +374
if (request.operation === 'execute_command') {
const stdout = typeof value.stdout === 'string' ? value.stdout : null;
const stderr = typeof value.stderr === 'string' ? value.stderr : null;
const outputLimit = request.maxOutputBytes ?? DEFAULT_COMMAND_OUTPUT_BYTES;
return (
hasOnlyKeys(value, COMMAND_RESULT_KEYS) &&
stdout != null &&
stderr != null &&
Buffer.from(stdout).toString('utf8') === stdout &&
Buffer.from(stderr).toString('utf8') === stderr &&
new TextEncoder().encode(stdout).byteLength + new TextEncoder().encode(stderr).byteLength <=
outputLimit &&
(value.exitCode === null ||
(Number.isSafeInteger(value.exitCode) &&
Number(value.exitCode) >= 0 &&
Number(value.exitCode) <= 255)) &&
(value.signal == null ||
(typeof value.signal === 'string' &&
value.signal.length <= MAX_COMMAND_SIGNAL_LENGTH &&
/^SIG[A-Z0-9]+$/.test(value.signal))) &&
typeof value.timedOut === 'boolean' &&
(value.exitCode === null
? value.timedOut === true || value.signal != null
: value.timedOut === false && value.signal == null)
);
}
Comment on lines +104 to +109
{
name: BashExecutionToolDefinition.name,
description: ATTACHED_WORKSPACE_BASH_DESCRIPTION,
schema: ATTACHED_WORKSPACE_BASH_SCHEMA,
responseFormat: 'content_and_artifact',
},
return (
typeof value === 'string' &&
Buffer.from(value).toString('utf8') === value &&
new TextEncoder().encode(value).byteLength <= maximum
Comment on lines +23 to +31
const bashSchema = BashExecutionToolDefinition.schema as {
properties?: NonNullable<LCTool['parameters']>['properties'];
};
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.',
};
Base automatically changed from danny-avila/code-workspace-list to dev September 4, 2026 14:52
@danny-avila
danny-avila force-pushed the danny-avila/code-workspace-command branch from 08a48d8 to 4be4d64 Compare September 4, 2026 15:37
@danny-avila danny-avila changed the title 🎒 feat(code): Run Bash in Attached Workspaces 🛻 feat: Route Bash Through Attached Workspaces Sep 4, 2026
@danny-avila
danny-avila merged commit fddf7e3 into dev Sep 4, 2026
31 checks passed
@danny-avila
danny-avila deleted the danny-avila/code-workspace-command branch September 4, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants