fix(bash,pwsh,fs,ptc): reject unadvertised arguments before pairing and approval

Without a sandboxing backend, a lone sandbox_permissions or justification
failed the pairing check and asked the model to add the other field, and
bash/pwsh checked a disabled run_in_background only after an escalation
approval. Reject unadvertised escalation fields and a disabled background
request during argument validation in bash, pwsh, write/edit/apply_patch,
and run_code, and name both escalation fields in the message. Update the
upgrade guide to identify rc.2 shell records by message.

Refs #7869
This commit is contained in:
sjw1231 committed 2026-11-12 15:29:38 +08:00
1 parent 0fe47c32ba
commit efc62d7b06
17 files changed
+167 -81

No files matched your search

@@ -9,8 +9,8 @@
en: f67fb81f55897105
zh: f74bb4d9e995f156
/shell-and-read-image-failures-use-consolidated-error-codes/change:
en: 16595e7db2999ca3
zh: 42b44f7ea29ddfb1
en: 623c6bfe8ffcfe7d
zh: ee26abc3d312b93b
/shell-and-read-image-failures-use-consolidated-error-codes/migration:
en: 0e111ffbadee4e2e
zh: cb1e8d6ef74f5cee
en: 24d3f8972933bbe6
zh: f03379efdb5809b2
@@ -13,16 +13,18 @@ Three `tool/result` error identities recorded by v0.2.2-rc.2 change:
| Failure | v0.2.2-rc.2 | Now |
| --- | --- | --- |
| `bash` or `pwsh` receives `sandbox_permissions` in a composition without a sandboxing executor | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` |
| `bash` or `pwsh` receives `sandbox_permissions` and `justification` in a composition without a sandboxing executor | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` |
| `bash` or `pwsh` receives `run_in_background: true` with `enableRunInBackground: false` | `JobError` / `JOB_BACKGROUND_DISABLED` | `ToolArgsError` / `INVALID_ARGS` |
| `read_image` runs on a model route without image input | `ImageInputError` / `IMAGE_UNSUPPORTED_MODEL` | `ImageInputError` / `MODEL_DOES_NOT_SUPPORT_IMAGES` |
In both shell cases the schema does not advertise the rejected argument, so the model's fix is to drop it. Both shell messages now start with `invalid arguments: `, which the model and transcript readers see. `SANDBOX_ESCALATION_UNAVAILABLE` remains for compositions that cannot route an approval.
In both shell cases the schema does not advertise the rejected argument, so the model's fix is to drop it. When only one of `sandbox_permissions` and `justification` reaches `bash`, `pwsh`, `write`, `edit`, or `apply_patch` without a sandboxing backend, the call previously failed the pairing check with `SandboxEscalationError` / `SANDBOX_ESCALATION_INVALID_ARGUMENT`; it now reports `INVALID_ARGS` as well. These calls are rejected before any approval request.
The shell messages now start with `invalid arguments: `, and the escalation message names both fields: `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`. `SANDBOX_ESCALATION_UNAVAILABLE` keeps its meaning for compositions that have a sandboxing executor but no approval service, calling Agent, or approval channel.
`JOB_BACKGROUND_DISABLED` is removed from `JOB_ERROR_CODES` and the `JobErrorCode` type in `@deepseek-ai/dsh-jobs`. `ImageInputErrorCode` in `@deepseek-ai/dsh-tool-fs` replaces `IMAGE_UNSUPPORTED_MODEL` with `MODEL_DOES_NOT_SUPPORT_IMAGES`, the value subagent attachments and Session attachment rejections already use.
## Migration
1. In analytics or retry rules that read `tool/result` `error`, map `JOB_BACKGROUND_DISABLED` and the shell `SANDBOX_ESCALATION_UNAVAILABLE` case to `INVALID_ARGS`, and `IMAGE_UNSUPPORTED_MODEL` to `MODEL_DOES_NOT_SUPPORT_IMAGES`. Session logs written by v0.2.2-rc.2 keep the old values.
1. In analytics or retry rules that read `tool/result` `error`, treat v0.2.2-rc.2 `JOB_BACKGROUND_DISABLED` results as `INVALID_ARGS` and `IMAGE_UNSUPPORTED_MODEL` as `MODEL_DOES_NOT_SUPPORT_IMAGES`. For `SANDBOX_ESCALATION_UNAVAILABLE`, `error` alone does not identify the shell case: treat a v0.2.2-rc.2 `bash` or `pwsh` result as `INVALID_ARGS` only when its message contains `no sandboxing executor to escalate`, and keep every other `SANDBOX_ESCALATION_UNAVAILABLE` result unchanged. Session logs keep the values they were written with.
2. Replace TypeScript references to `'JOB_BACKGROUND_DISABLED'` or `'IMAGE_UNSUPPORTED_MODEL'`; `pnpm run typecheck` reports any that remain.
3. Update text matchers that expect the shell messages without the `invalid arguments: ` prefix.
3. Update text matchers that expect the earlier shell messages, which had no `invalid arguments: ` prefix and named only `sandbox_permissions`.
@@ -13,16 +13,18 @@ v0.2.2-rc.2 记录的三种 `tool/result` 错误标识发生变化:
| 失败 | v0.2.2-rc.2 | 现在 |
| --- | --- | --- |
| 在没有沙箱执行器的组合中,`bash` 或 `pwsh` 收到 `sandbox_permissions` | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` |
| 在没有沙箱执行器的组合中,`bash` 或 `pwsh` 收到 `sandbox_permissions` 与 `justification` | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` |
| `enableRunInBackground: false` 时,`bash` 或 `pwsh` 收到 `run_in_background: true` | `JobError` / `JOB_BACKGROUND_DISABLED` | `ToolArgsError` / `INVALID_ARGS` |
| `read_image` 运行在不支持图像输入的模型路由上 | `ImageInputError` / `IMAGE_UNSUPPORTED_MODEL` | `ImageInputError` / `MODEL_DOES_NOT_SUPPORT_IMAGES` |
两个 shell 情形中,被拒绝的参数都没有出现在 schema 里,模型的修正办法是去掉它。这两条 shell 消息现在以 `invalid arguments: ` 开头,模型和对话记录的读者都能看到。`SANDBOX_ESCALATION_UNAVAILABLE` 仍用于组合无法发起审批的情形。
两个 shell 情形中,被拒绝的参数都没有出现在 schema 里,模型的修正办法是去掉它。在没有沙箱后端时,若 `bash`、`pwsh`、`write`、`edit` 或 `apply_patch` 只收到 `sandbox_permissions` 与 `justification` 之一,此前会在配对校验中以 `SandboxEscalationError` / `SANDBOX_ESCALATION_INVALID_ARGUMENT` 失败;现在同样报 `INVALID_ARGS`。这些调用会在任何审批请求之前被拒绝。
shell 消息现在以 `invalid arguments: ` 开头,升权消息同时点名两个字段:`invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`。对于有沙箱执行器、但缺少审批服务、调用方 Agent 或审批通道的组合,`SANDBOX_ESCALATION_UNAVAILABLE` 的含义不变。
`@deepseek-ai/dsh-jobs` 的 `JOB_ERROR_CODES` 与 `JobErrorCode` 类型删除了 `JOB_BACKGROUND_DISABLED`。`@deepseek-ai/dsh-tool-fs` 的 `ImageInputErrorCode` 用 `MODEL_DOES_NOT_SUPPORT_IMAGES` 替换 `IMAGE_UNSUPPORTED_MODEL`,子 agent 附件与 Session 附件拒绝已在使用这个值。
## 迁移
1. 读取 `tool/result` `error` 的统计或重试规则中,把 `JOB_BACKGROUND_DISABLED` 与 shell 的 `SANDBOX_ESCALATION_UNAVAILABLE` 情形映射为 `INVALID_ARGS`,把 `IMAGE_UNSUPPORTED_MODEL` 映射为 `MODEL_DOES_NOT_SUPPORT_IMAGES`。v0.2.2-rc.2 写入的 Session 日志保留旧值。
1. 读取 `tool/result` `error` 的统计或重试规则中,把 v0.2.2-rc.2 的 `JOB_BACKGROUND_DISABLED` 结果视为 `INVALID_ARGS`,把 `IMAGE_UNSUPPORTED_MODEL` 视为 `MODEL_DOES_NOT_SUPPORT_IMAGES`。仅凭 `error` 无法从 `SANDBOX_ESCALATION_UNAVAILABLE` 中分出 shell 情形:只有 v0.2.2-rc.2 的 `bash` 或 `pwsh` 结果的消息含 `no sandboxing executor to escalate` 时,才视为 `INVALID_ARGS`;其余 `SANDBOX_ESCALATION_UNAVAILABLE` 结果保持原义。Session 日志保留写入时的值。
2. 替换 TypeScript 中对 `'JOB_BACKGROUND_DISABLED'` 或 `'IMAGE_UNSUPPORTED_MODEL'` 的引用;`pnpm run typecheck` 会报出剩余的引用。
3. 更新那些期望 shell 消息不带 `invalid arguments: ` 前缀的文本匹配。
3. 更新那些期望旧 shell 消息的文本匹配:旧消息没有 `invalid arguments: ` 前缀,且只点名 `sandbox_permissions`。
+7 -3
View File
@@ -403,6 +403,10 @@ export function createRunCodeTransport(
}
const runtime = getRuntime()
const run = async (callSignal: AbortSignal): Promise<RunCodeOutput> => {
// The schema omits both fields without runtime confinement; reject them before pairing checks.
if (runtime.sandboxMode === undefined && (args.sandbox_permissions !== undefined || args.justification !== undefined)) {
throw new ToolArgsError(['sandbox_permissions and justification are not available for this PTC runtime'])
}
validateEscalationArgs(args.sandbox_permissions, args.justification)
if (args.timeoutMs !== undefined && runtime.timeout === undefined) {
throw new ToolArgsError(['timeoutMs is not available for this PTC runtime'])
@@ -413,17 +417,17 @@ export function createRunCodeTransport(
const standingPolicy = runtime.sandboxMode === undefined ? undefined : resolveSandboxPolicy(ctx, exec)
let policy = standingPolicy
if (args.sandbox_permissions !== undefined && args.justification !== undefined) {
if (standingPolicy === undefined) throw new ToolArgsError(['sandbox_permissions is not available for this PTC runtime'])
const confined = standingPolicy as SandboxExecutionPolicy
const approvedMode = await approveEscalation({
requestedMode: args.sandbox_permissions,
justification: args.justification,
effectiveMode: standingPolicy.mode,
effectiveMode: confined.mode,
subject: 'program',
}, {
approver: ctx.get('approval'), agent: exec.agent, callId: exec.callId,
toolName, signal: callSignal,
})
policy = { ...standingPolicy, mode: approvedMode }
policy = { ...confined, mode: approvedMode }
}
const cwd = await resolveWorkingDirectory(ctx, { ...exec, signal: callSignal })
callSignal.throwIfAborted()
@@ -2890,15 +2890,19 @@ describe('per-program execution controls', () => {
} finally { await ctx.fiber.dispose() }
})
it('rejects escalation fields for a runtime without confinement support', async () => {
it.each([
{ sandbox_permissions: 'workspace-write', justification: 'Need file writes' },
{ sandbox_permissions: 'workspace-write' },
{ justification: 'Need file writes' },
])('rejects escalation fields for a runtime without confinement support: %o', async (fields) => {
const { ctx, tools, runtime } = await setup()
try {
const result = await tools.execute({
callId: brandString<ToolCallId>('unsupported-escalation'), name: RUN_CODE_NAME, signal: testToolSignal,
arguments: { code: 'return 1', description: 'Try an unsupported mode', sandbox_permissions: 'workspace-write', justification: 'Need file writes' },
arguments: { code: 'return 1', description: 'Try an unsupported mode', ...fields },
})
expect(result.isError).toBe(true)
expect(JSON.stringify(result.content)).toContain('sandbox_permissions is not available for this PTC runtime')
expect(JSON.stringify(result.content)).toContain('invalid arguments: sandbox_permissions and justification are not available for this PTC runtime')
expect(result.error?.info).toEqual({ name: 'ToolArgsError', code: 'INVALID_ARGS' })
expect(runtime.lastRequest).toBeUndefined()
} finally { await ctx.fiber.dispose() }
+4 -3
View File
@@ -87,6 +87,10 @@ export class FsSandboxController {
* unsandboxed backend.
*/
async resolvePolicy(toolName: string, args: FsEscalationArgs, exec: ToolExecution): Promise<SandboxExecutionPolicy | undefined> {
// The schema omits both fields without a sandboxing filesystem; reject them before pairing checks.
if (this.escalationModes.length === 0 && (args.sandbox_permissions !== undefined || (args.justification ?? '').trim() !== '')) {
throw new ToolArgsError(['sandbox_permissions and justification are not available in this composition (no sandboxing filesystem to escalate)'])
}
const standingPolicy = this.policy?.resolve({ ...exec.agent ? { session: exec.agent.session } : {} })
if (args.sandbox_permissions !== undefined && args.sandbox_permissions === standingPolicy?.mode) return standingPolicy
const justification = args.sandbox_permissions === undefined && args.justification?.trim() === ''
@@ -96,9 +100,6 @@ export class FsSandboxController {
if (args.sandbox_permissions === undefined || args.justification === undefined) {
return standingPolicy
}
if (this.escalationModes.length === 0) {
throw new ToolArgsError(['sandbox_permissions is not available in this composition (no sandboxing filesystem to escalate)'])
}
const policy = standingPolicy as SandboxExecutionPolicy
const approvedMode = await approveEscalation(
{ requestedMode: args.sandbox_permissions, justification: args.justification, effectiveMode: policy.mode, subject: 'operation' },
+7 -3
View File
@@ -1146,11 +1146,15 @@ describe('sandbox escalation API (write/edit)', () => {
expect(text(orphan)).toContain('justification is only valid together with sandbox_permissions')
})
it('sandbox_permissions under a non-confining backend fails closed (unadvertised field still reaches execute)', async () => {
it.each([
{ sandbox_permissions: 'workspace-write', justification: 'why' },
{ sandbox_permissions: 'workspace-write' },
{ justification: 'why' },
])('rejects unadvertised escalation fields under a non-confining backend as argument errors: %o', async (fields) => {
const { ctx } = await setup()
const result = await call(ctx, 'write', { file_path: 'a.txt', content: 'x', sandbox_permissions: 'workspace-write', justification: 'why' }, escalationAgent())
const result = await call(ctx, 'write', { file_path: 'a.txt', content: 'x', ...fields }, escalationAgent())
expect(result.isError).toBe(true)
expect(text(result)).toContain('not available in this composition')
expect(text(result)).toContain('invalid arguments: sandbox_permissions and justification are not available in this composition')
expect(result.error?.info).toEqual({ name: 'ToolArgsError', code: 'INVALID_ARGS' })
})
})
+4 -4
View File
@@ -33,8 +33,8 @@
en: 472beeb895ca46cf
zh: ba110c9f62f7d5b8
/deepseek-ai-dsh-tool-bash/use-this-package/what-can-go-wrong:
en: c1f4b88a5fd84616
zh: 8f7328b9edab462f
en: 52c02853f32bf6f9
zh: 77355e3df066527b
/deepseek-ai-dsh-tool-bash/understand-the-implementation:
en: 165313776a851b51
zh: 828f48807036aff0
@@ -111,8 +111,8 @@
en: 2d4f2c8605eccab3
zh: 67f1f0218f73c6bf
/deepseek-ai-dsh-tool-bash/model-experience/tool-errors/what-the-model-sees:
en: 5dc3bd182ef54b08
zh: be8a55f8aefada5a
en: a59c3d16f59c7577
zh: 24dd44d419e240a0
/deepseek-ai-dsh-tool-bash/model-experience/tool-errors/token-effect:
en: a3a78ef476ec5e56
zh: dd2c8ad0f69e8ff1
+2 -2
View File
@@ -71,7 +71,7 @@ When the mounted executor confines commands (for example `dsh-bash-sandbox`), a
### What can go wrong
A composition with no executor provider never activates the tool. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` without a sandboxing executor fails with `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`. `enableRunInBackground: false` removes the parameter and rejects a forced background call at execution time.
A composition with no executor provider never activates the tool. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` or `justification` without a sandboxing executor fails with `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`. `enableRunInBackground: false` removes the parameter and rejects a forced background call at execution time.
-----
@@ -196,7 +196,7 @@ Append-only; newly visible content follows the reusable request prefix and does
#### What the model sees
Validation and policy failures are normalized as `Error: <message>`. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got <value>`, the escalation pairing failures, `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` or `run_in_background` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled.
Validation and policy failures are normalized as `Error: <message>`. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got <value>`, the escalation pairing failures, `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including `sandbox_permissions`, `justification`, or `run_in_background` when the schema does not advertise them, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled.
#### Token effect
+2 -2
View File
@@ -71,7 +71,7 @@ kind: "package-reference"
### 可能出什么问题
没有执行器提供方的组合永远不会激活该工具。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时的 `sandbox_permissions` 会以 `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)` 失败。`enableRunInBackground: false` 会移除该参数,并在执行时拒绝强制后台调用。
没有执行器提供方的组合永远不会激活该工具。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时传入 `sandbox_permissions` 或 `justification` 会以 `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)` 失败。`enableRunInBackground: false` 会移除该参数,并在执行时拒绝强制后台调用。
-----
@@ -196,7 +196,7 @@ renderer 输出依数据而定的 stdout 尾部,再输出可选的 `[stderr]`
#### 模型看到什么
验证与策略失败统一为 `Error: <message>`。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got <value>`、升权配对失败、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。
验证与策略失败统一为 `Error: <message>`。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got <value>`、升权配对失败、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions`、`justification` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。
#### Token 影响
+36 -15
View File
@@ -72,7 +72,35 @@ interface BashToolArgs {
justification?: string
}
function validateBashArgs(args: BashToolArgs, effectiveMode: SandboxMode | undefined): void {
/** Which optional argument groups the registered schema advertises in this composition. */
interface AdvertisedArgs {
/** `sandbox_permissions` and `justification`; advertised only with a sandboxing executor. */
escalation: boolean
/** `run_in_background`; advertised unless `enableRunInBackground: false`. */
background: boolean
}
/**
* Reject arguments the schema does not advertise. Schema validation checks
* advertised keys only, so these still reach `execute`; the model fixes the call
* by dropping them, which makes them argument errors. Runs before escalation
* pairing checks, approval, and working-directory setup.
* @param args - the call's arguments.
* @param advertised - the argument groups this composition advertises.
*/
function rejectUnadvertisedArgs(
args: { sandbox_permissions?: string; justification?: string; run_in_background?: boolean },
advertised: AdvertisedArgs,
): void {
if (!advertised.escalation && (args.sandbox_permissions !== undefined || (args.justification ?? '').trim() !== '')) {
throw new ToolArgsError(['sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)'])
}
if (!advertised.background && args.run_in_background === true) {
throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)'])
}
}
function validateBashArgs(args: BashToolArgs, effectiveMode: SandboxMode | undefined, advertised: AdvertisedArgs): void {
if (args.command.trim().length === 0) {
throw new ToolArgsError(['invalid command: expected a non-empty string'])
}
@@ -82,6 +110,7 @@ function validateBashArgs(args: BashToolArgs, effectiveMode: SandboxMode | undef
if (args.timeoutMs !== undefined && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) {
throw new ToolArgsError([`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`])
}
rejectUnadvertisedArgs(args, advertised)
if (args.sandbox_permissions !== undefined && args.sandbox_permissions === effectiveMode) return
const justification = args.sandbox_permissions === undefined && args.justification?.trim() === ''
? undefined
@@ -233,12 +262,11 @@ export function apply(ctx: Context, config: Config = {}): void {
* Resolve a sandbox-escalation request through `ctx.approval` BEFORE
* anything executes, delegating the shared fail-closed sequence (strict
* widening, channel resolution, outcome mapping) to
* {@link approveEscalation}. This tool contributes only the composition
* guard (the fields are unadvertised without a sandboxing executor, yet
* schema validation checks advertised keys only, so an unadvertised
* `sandbox_permissions` still reaches execute) and the approval
* ingredients. The shared policy resolver is required whenever the executor
* advertises confinement, so a split composition fails at tool-plugin load.
* {@link approveEscalation}. This tool contributes only the approval
* ingredients; {@link validateBashArgs} has already rejected the fields when
* no sandboxing executor advertises them. The shared policy resolver is
* required whenever the executor advertises confinement, so a split
* composition fails at tool-plugin load.
*/
const approveBashEscalation = (
mode: string,
@@ -246,9 +274,6 @@ export function apply(ctx: Context, config: Config = {}): void {
exec: ToolExecution,
standingPolicy: SandboxExecutionPolicy | undefined,
): Promise<SandboxMode> => {
if (escalationModes.length === 0) {
throw new ToolArgsError(['sandbox_permissions is not available in this composition (no sandboxing executor to escalate)'])
}
const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode
return approveEscalation(
{ requestedMode: mode, justification, effectiveMode, subject: 'command' },
@@ -498,7 +523,7 @@ export function apply(ctx: Context, config: Config = {}): void {
async execute(args: BashToolArgs, exec) {
// Description is display metadata; workdir defaults to the caller's session.
const standingPolicy = resolveSandboxPolicy(exec)
validateBashArgs(args, standingPolicy?.mode)
validateBashArgs(args, standingPolicy?.mode, { escalation: escalationModes.length > 0, background: backgroundEnabled })
const approvedMode = args.sandbox_permissions !== undefined && args.justification !== undefined
? await approveBashEscalation(args.sandbox_permissions, args.justification, exec, standingPolicy)
: undefined
@@ -516,10 +541,6 @@ export function apply(ctx: Context, config: Config = {}): void {
...policy !== undefined ? { sandboxPolicy: policy } : {},
}
if (args.run_in_background === true) {
// Undeclared keys are allowed, so schema omission also needs enforcement.
if (!backgroundEnabled) {
throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)'])
}
if (jobs === undefined) {
throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs')
}
+19 -5
View File
@@ -215,7 +215,7 @@ class CountingStartExecutor extends ShellExecutor {
}
}
async function setupSandboxed(withApproval = false) {
async function setupSandboxed(withApproval = false, toolConfig: Partial<ToolBash.Config> = {}) {
const ctx = new Context()
provideWorkingDirectoryFixture(ctx)
await ctx.plugin(SystemPrompt)
@@ -229,7 +229,7 @@ async function setupSandboxed(withApproval = false) {
await ctx.plugin(RecordingSandboxExecutor)
if (withApproval) await ctx.plugin(ApprovalService)
await ctx.plugin(BashEnvPlugin)
await ctx.plugin(ToolBash)
await ctx.plugin(ToolBash, toolConfig)
return { ctx, bash: ctx.shell as RecordingSandboxExecutor }
}
@@ -798,11 +798,25 @@ describe('sandbox escalation through the generic task producer', () => {
}
})
it('rejects a forced background call before asking for an escalation', async () => {
const { ctx, bash } = await setupSandboxed(true, { enableRunInBackground: false })
const prompted = vi.fn()
ctx.on('approval/request', () => { prompted(); return Promise.resolve<ApprovalOutcome>('allowed-once') })
const result = await call(ctx, 'bash', { ...escalate, run_in_background: true }, sandboxAgent())
expect(text(result)).toContain('invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)')
expect(result).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } })
expect(prompted).not.toHaveBeenCalled()
expect(bash.modes).toEqual([])
})
it('rejects injected escalation without a sandbox and narrower escalation without prompting', async () => {
const plain = await setup()
const unavailable = await call(plain, 'bash', escalate)
expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions is not available in this composition')
expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } })
const { command, description, sandbox_permissions, justification } = escalate
for (const args of [escalate, { command, description, sandbox_permissions }, { command, description, justification }]) {
const unavailable = await call(plain, 'bash', args)
expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions and justification are not available in this composition')
expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } })
}
const { ctx } = await setupSandboxed(true)
const prompted = vi.fn()
+4 -4
View File
@@ -33,8 +33,8 @@
en: 76f3f791f53d1005
zh: e5b262db24e6eb83
/deepseek-ai-dsh-tool-pwsh/use-this-package/what-can-go-wrong:
en: b59d36b896c2d2e8
zh: f0145138ec8ca116
en: 4a1fae5d79a4d13d
zh: 0b5206086a58ee9c
/deepseek-ai-dsh-tool-pwsh/understand-the-implementation:
en: 165313776a851b51
zh: 828f48807036aff0
@@ -108,8 +108,8 @@
en: 2d4f2c8605eccab3
zh: 67f1f0218f73c6bf
/deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/what-the-model-sees:
en: efc9d4c72556b355
zh: 9b959bb612d39108
en: 828df448c1128f2f
zh: 720c590c01089651
/deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/token-effect:
en: 243bad012dd99c7f
zh: 5ee74905020bd49a
+2 -2
View File
@@ -66,7 +66,7 @@ Under a sandboxing executor, denied commands report `[sandbox: file access denie
### What can go wrong
A composition with no PowerShell executor never activates the tool, and the injected services (`tools`, `shell`, `systemPrompt`, `shellEnv`) must all exist. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` without a sandboxing executor fails with `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`.
A composition with no PowerShell executor never activates the tool, and the injected services (`tools`, `shell`, `systemPrompt`, `shellEnv`) must all exist. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` or `justification` without a sandboxing executor fails with `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`.
-----
@@ -188,7 +188,7 @@ Append-only; newly visible content follows the reusable request prefix and does
#### What the model sees
Validation and infrastructure failures are normalized as `Error: <message>`. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got <value>`, the escalation pairing failures, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the shared escalation failures (not strictly wider / no approval service / no agent to route / no approval channel / user rejected / was cancelled), `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` or `run_in_background` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled.
Validation and infrastructure failures are normalized as `Error: <message>`. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got <value>`, the escalation pairing failures, `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`, the shared escalation failures (not strictly wider / no approval service / no agent to route / no approval channel / user rejected / was cancelled), `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including `sandbox_permissions`, `justification`, or `run_in_background` when the schema does not advertise them, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled.
#### Token effect
+2 -2
View File
@@ -66,7 +66,7 @@ kind: "package-reference"
### 可能出什么问题
没有 PowerShell 执行器的组合永远不会激活该工具,且注入的服务(`tools`、`shell`、`systemPrompt`、`shellEnv`)必须全部存在。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时的 `sandbox_permissions` 会以 `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)` 失败。
没有 PowerShell 执行器的组合永远不会激活该工具,且注入的服务(`tools`、`shell`、`systemPrompt`、`shellEnv`)必须全部存在。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时传入 `sandbox_permissions` 或 `justification` 会以 `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)` 失败。
-----
@@ -188,7 +188,7 @@ Non-zero exits are reported as `[exit code: N]` markers; investigate failures be
#### 模型看到什么
验证与基础设施失败统一为 `Error: <message>`。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got <value>`、升权配对失败、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、共享升权失败(未严格加宽/无审批服务/无 agent 可路由/无审批通道/用户拒绝/已取消)、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。
验证与基础设施失败统一为 `Error: <message>`。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got <value>`、升权配对失败、`invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`、共享升权失败(未严格加宽/无审批服务/无 agent 可路由/无审批通道/用户拒绝/已取消)、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions`、`justification` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。
#### Token 影响
+36 -16
View File
@@ -106,7 +106,35 @@ interface PwshForegroundResult {
}
/* jscpd:ignore-start -- minimal mirror of dsh-tool-bash's validation and execute plumbing (Agent Note). */
function validatePwshArgs(args: PwshToolArgs): void {
/** Which optional argument groups the registered schema advertises in this composition. */
interface AdvertisedArgs {
/** `sandbox_permissions` and `justification`; advertised only with a sandboxing executor. */
escalation: boolean
/** `run_in_background`; advertised unless `enableRunInBackground: false`. */
background: boolean
}
/**
* Reject arguments the schema does not advertise. Schema validation checks
* advertised keys only, so these still reach `execute`; the model fixes the call
* by dropping them, which makes them argument errors. Runs before escalation
* pairing checks, approval, and working-directory setup.
* @param args - the call's arguments.
* @param advertised - the argument groups this composition advertises.
*/
function rejectUnadvertisedArgs(
args: { sandbox_permissions?: string; justification?: string; run_in_background?: boolean },
advertised: AdvertisedArgs,
): void {
if (!advertised.escalation && (args.sandbox_permissions !== undefined || (args.justification ?? '').trim() !== '')) {
throw new ToolArgsError(['sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)'])
}
if (!advertised.background && args.run_in_background === true) {
throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)'])
}
}
function validatePwshArgs(args: PwshToolArgs, advertised: AdvertisedArgs): void {
if (args.command.trim().length === 0) {
throw new ToolArgsError(['invalid command: expected a non-empty string'])
}
@@ -116,6 +144,7 @@ function validatePwshArgs(args: PwshToolArgs): void {
if (args.timeoutMs !== undefined && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) {
throw new ToolArgsError([`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`])
}
rejectUnadvertisedArgs(args, advertised)
validateEscalationArgs(args.sandbox_permissions, args.justification)
}
/* jscpd:ignore-end */
@@ -245,13 +274,11 @@ export function apply(ctx: Context, config: Config = {}): void {
* Resolve a sandbox-escalation request through `ctx.approval` BEFORE
* anything executes, delegating the shared fail-closed sequence (strict
* widening, channel resolution, outcome mapping) to
* {@link approveEscalation}. This tool contributes only the composition
* guard (the fields are unadvertised without a sandboxing executor, yet
* schema validation checks advertised keys only, so an unadvertised
* `sandbox_permissions` still reaches execute) and the approval
* ingredients. The shared policy resolver is required whenever the
* executor advertises confinement, so a split composition fails at
* tool-plugin load.
* {@link approveEscalation}. This tool contributes only the approval
* ingredients; {@link validatePwshArgs} has already rejected the fields when
* no sandboxing executor advertises them. The shared policy resolver is
* required whenever the executor advertises confinement, so a split
* composition fails at tool-plugin load.
*/
const approvePwshEscalation = (
mode: string,
@@ -259,9 +286,6 @@ export function apply(ctx: Context, config: Config = {}): void {
exec: ToolExecution,
standingPolicy: SandboxExecutionPolicy | undefined,
): Promise<SandboxMode> => {
if (escalationModes.length === 0) {
throw new ToolArgsError(['sandbox_permissions is not available in this composition (no sandboxing executor to escalate)'])
}
const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode
return approveEscalation(
{ requestedMode: mode, justification, effectiveMode, subject: 'command' },
@@ -520,7 +544,7 @@ export function apply(ctx: Context, config: Config = {}): void {
},
/* jscpd:ignore-start -- the execute path mirrors dsh-tool-bash's by design (see the pwsh-tool-and-executor Agent Note). */
async execute(args: PwshToolArgs, exec) {
validatePwshArgs(args)
validatePwshArgs(args, { escalation: escalationModes.length > 0, background: backgroundEnabled })
// Description is display metadata; workdir defaults to the caller's session.
const standingPolicy = resolveSandboxPolicy(exec)
const approvedMode = args.sandbox_permissions !== undefined && args.justification !== undefined
@@ -539,10 +563,6 @@ export function apply(ctx: Context, config: Config = {}): void {
...policy !== undefined ? { sandboxPolicy: policy } : {},
}
if (args.run_in_background === true) {
// Undeclared keys are allowed, so schema omission also needs enforcement.
if (!backgroundEnabled) {
throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)'])
}
if (jobs === undefined) {
throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs')
}
+19 -5
View File
@@ -228,7 +228,7 @@ class ConfiningFakeBash extends ShellExecutor {
}
/** Sandboxed composition: the shared policy service + a confining executor + the pwsh tool (+ optional approval). */
async function setupSandboxed(withApproval = false) {
async function setupSandboxed(withApproval = false, toolConfig: Partial<ToolPwsh.Config> = {}) {
const ctx = new Context()
provideWorkingDirectoryFixture(ctx)
await ctx.plugin(SystemPrompt)
@@ -245,7 +245,7 @@ async function setupSandboxed(withApproval = false) {
await ctx.plugin(SandboxPolicyService, {})
await ctx.plugin(ConfiningFakeBash)
if (withApproval) await ctx.plugin(ApprovalService)
await ctx.plugin(ToolPwsh)
await ctx.plugin(ToolPwsh, toolConfig)
const bash = ctx.shell as ConfiningFakeBash
return { ctx, bash }
}
@@ -682,11 +682,25 @@ describe('sandbox escalation through ctx.approval', () => {
expect(schema.parameters.properties).not.toHaveProperty('sandbox_permissions')
})
it('rejects a forced background call before asking for an escalation', async () => {
const { ctx, bash } = await setupSandboxed(true, { enableRunInBackground: false })
const prompted = vi.fn()
ctx.on('approval/request', () => { prompted(); return Promise.resolve<ApprovalOutcome>('allowed-once') })
const result = await call(ctx, 'pwsh', { ...escalate, run_in_background: true }, sandboxAgent())
expect(text(result)).toContain('invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)')
expect(result).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } })
expect(prompted).not.toHaveBeenCalled()
expect(bash.modes).toEqual([])
})
it('rejects injected escalation without a sandbox and narrower escalation without prompting', async () => {
const plain = await setup()
const unavailable = await call(plain.ctx, 'pwsh', escalate)
expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions is not available in this composition')
expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } })
const { command, description, sandbox_permissions, justification } = escalate
for (const args of [escalate, { command, description, sandbox_permissions }, { command, description, justification }]) {
const unavailable = await call(plain.ctx, 'pwsh', args)
expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions and justification are not available in this composition')
expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } })
}
const { ctx } = await setupSandboxed(true)
const prompted = vi.fn()