dsh-plugin-pyrun: One-Step Execution of Python Source Code in DSH

Preface

In DeepSeek Harness (DSH), a common approach to running a short Python snippet with a model involves writing a temporary script to disk and then invoking it via shell or PowerShell. In Windows and PowerShell environments, this path often must deal with quote escaping, command-line length limits, and garbled text caused by console encoding inconsistencies with UTF-8 source code. dsh-plugin-pyrun consolidates “give source code, get results” into a single tool call: the source code is written to the subprocess’s stdin via JSON parameters, interpreted by python -X utf8 -u -, and stdout/stderr are returned after being decoded as UTF-8. It shares the same sandbox policies and background job semantics as the built-in pwsh tool.

What is this

dsh-plugin-pyrun is a community-maintained DSH plugin (Directory: ds-hu/dsh-plugin-pyrun, Source: GitHub), categorized under model inference. It registers the tool name python within the harness, targeting scenarios where “the model directly provides the raw Python program text and returns execution results in one step.” It supports foreground waiting, background jobs, and one-time permission escalation retries via the approval workflow when sandbox rejection occurs.

Core Features

Direct stdin injection, bypassing the shell quoting layer

Instead of concatenating source code into argv, the tool writes the raw program text corresponding to the code parameter into the stdin of the Python subprocess, equivalent to:

python -X utf8 -u -

The combination of -X utf8 and full-chain UTF-8 decoding mitigates GBK interference on Windows; -u reduces buffering to facilitate timely output viewing. Compared to “passing parameters via shell,” it eliminates the quote escaping layer and avoids typical command-line length limits.

Foreground and Background Modes

Foreground calls wait for the process to finish. The result marks non-zero exit codes with [exit code: N] (treated as a result rather than a tool error). timeout_ms can be set (subject to deployment limits); timeouts and aborts are marked as [timed out after Nms] and [aborted] respectively. stderr is separated by [stderr] sections; excessive output is truncated at the tail with a [output truncated; full output: <path>] notice.

Background mode returns a job ID immediately when run_in_background is passed; timeout_ms and background mode are mutually exclusive, and passing both simultaneously will be rejected. In the job roster, the kind is python. Output is harvested using job_output, stopped using job_kill, and viewed using job_list, aligning semantics with the built-in pwsh tool.

Sandbox and One-time Escalation

By default, it is constrained by DSH sandboxing. If access is denied due to file operations etc., a one-time retry can be initiated in the same turn using sandbox_permissions combined with justification. The approval panel displays the explanation text; upon rejection, the result includes [sandbox: file access denied under <mode> mode] and an escalation prompt.

Installation and Activation

The installation example in the README uses link: to point to the local plugin directory (this only creates a profile symlink and does not install plugin dependencies to the profile root; simply restart dsh after code changes to load it):

dsh plugin --profile web add link:D:/Projects/dsh-plugin-pyrun

Replace the path with the root directory of your locally cloned or extracted plugin. If using dsh plugin add to write to ~/.dsh and perform pnpm installation, a one-time escalation might be required in restricted sandboxes; this package declares dsh.bundle.patch, and upon successful installation, it enters the profile as a bundle layer.

After installation, dsh must be restarted: the host side is a Node ESM module, and plugin code is only reloaded upon restart.

Version and Dependency Gates

peerDependencies in package.json require @deepseek-ai/dsh-tools and @deepseek-ai/dsh-sandbox to be ^0.2.0-rc.1, and must be paired with @deepseek-ai/cordis ^4.0.1. The host checks peers via semver at startup; if requirements are not met, the entire package is skipped (visible as “skipping profile bundle” in logs). The 0.1.x host will not load the current version; 0.1.x users need to use the historical commits in the repository targeting the 0.1.5-rc.2 contract. The runtime environment requires Node >=22.

The plugin author emphasizes: @deepseek-ai/dsh-tools and @deepseek-ai/dsh-sandbox should only appear in peerDependencies (and devDependencies for development). They must not be written into dependencies, otherwise, a second copy of the core package may appear in the profile, leading to tool dispatch Symbol splitting and in-process tool call failures.

Typical Usage

The tool name is python. Main parameters are as follows (types and meanings are subject to the README):

Parameter Type Description
code string (required) Raw Python program text
workdir string Working directory; defaults to session cwd
timeout_ms number Foreground timeout; not applicable for background
run_in_background boolean Run in background and return job id
sandbox_permissions enum One-time escalation retry for rejected calls
justification string One-sentence explanation for the approval panel

When the model or agent calls this tool in a conversation, simply put the complete source code into code. For long computations or streaming output observation, use run_in_background combined with job_output. When reading or writing files in a specific directory, limit the scope via workdir and comply with sandbox policies.

Use Cases and Notes

Suitable for teams that need to quickly verify algorithm snippets, data processing scripts, or short Python logic collaborated with models within the DSH agent loop, and wish to reduce the “write temp file + shell execution” steps. Background jobs are suitable for time-consuming tasks; sandbox and escalation behaviors are consistent with pwsh, facilitating unified policies within the same harness.

Please read the GitHub repository source code and MIT license before use. The plugin starts Python subprocesses under the current dsh process privileges; installation and escalation are equivalent to trusting the maintainer and local paths. The community directory SkillHub is an independent site with no official affiliation with DeepSeek / High-Flyer; stars and versions are subject to the repository page (current package version 0.1.0).

Conclusion

dsh-plugin-pyrun utilizes direct stdin injection and a full-chain UTF-8 approach to consolidate quick Python execution into a single tool within the harness, aligning with the sandbox and background job systems. If you are already running DSH on 0.2.x, you can integrate it via the README’s link: or profile installation methods, and invoke it via the tool python after restarting.

  • Directory: https://www.skillhub.cn/plugins/ds-hu/dsh-plugin-pyrun
  • GitHub: https://github.com/ds-hu/dsh-plugin-pyrun
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye