DeepSeek Harness Python SDK: DSH plugin programmatic use
DeepSeek Harness ships an official Python SDK: after pip install deepseek-harness-sdk, a DeepSeekHarness context manager drives a sdk-minimal profile from your Python code — configuration is composed from the profile, the home patch, and any patches you pass, and session logs land in $DSH_HOME/sessions as uncompressed JSONL (source).
Installing the DeepSeek Harness Python SDK
The prerequisites are Python 3.10+ and Git; run pip install deepseek-harness-sdk, and the install comes with a matching native runtime wheel and the dsh command, so normal SDK runs do not need system Node.js (source). Steps:
- Check platform and version — Linux x64/arm64, macOS 14+ on arm64, or Windows x64, plus a DeepSeek-compatible API endpoint and credentials. Expected: satisfy these first so the native wheel matches.
- Create an isolated environment — make and activate a virtualenv (Linux/macOS:
python -m venv .venvthen. .venv/bin/activate; Windows:py -3.10 -m venv .venvand activate). Expected:python -m pip install deepseek-harness-sdkinstalls into it. - Prepare an isolated workspace and home — use a disposable workspace and a separate
dsh_home. Expected: the SDK uses only the home you pass and never reads~/.dsh. - Export credentials — set
DEEPSEEK_API_KEY; with a compatible proxy also setDEEPSEEK_BASE_URL. Expected: credentials enter the runtime from the environment.
Running a task with DeepSeekHarness
In code, use DeepSeekHarness as a context manager with provider, model, cwd, dsh_home, and profile, call harness.run(prompt, session_id=...), and read result.final_response (source). Minimal usage:
from pathlib import Path
from deepseek_harness import DeepSeekHarness
workspace = Path("/absolute/path/to/disposable-workspace").resolve()
dsh_home = Path("/absolute/path/to/example-dsh-home").resolve()
with DeepSeekHarness(
provider="deepseek-official",
model="deepseek-v4-flash",
max_tokens=49_152,
cwd=str(workspace),
dsh_home=str(dsh_home),
profile="sdk-minimal",
) as harness:
result = harness.run(
"Inspect the repository and fix the failing tests.",
session_id="example-001",
)
print(result.final_response)
Key points:
- The process starts lazily — the SDK lazily starts an internal
dsh --profile sdk-minimalprocess and reuses it until the context manager exits. Expected: the process is reclaimed after thewithblock. - No separate Python runtime — there is no standalone Python runtime bin or a full set of configuration options; everything still goes through profiles and patches. Expected: concepts stay unified in DeepSeek Harness's own configuration system.
- New home to isolate, new session id for independent work — reuse the harness, home, and id only to continue the same persistent conversation. Expected: mixing them silently resumes the wrong session.
DSH plugins and the minimal profile: installing, patching, enabling str_replace_editor
Use dsh plugin to persist dependencies and bundle layers in that home; persist config changes in $DSH_HOME/profiles/sdk-minimal/cordis.patch.yml, or pass a patch from Python for one run (source). Three steps:
- Initialize the profile — run
dsh --profile sdk-minimal --dump-default-config >/dev/null. Expected: the bundled standalone profile is initialized. - Install a plugin bundle — use
dsh plugin --profile sdk-minimal add file:/absolute/path/to/my-plugin-bundle, which forwards package management topnpmand records every installed package that exports adsh.bundlelayer. Expected:pnpmis needed only for this management command, not to start an already-installed SDK. To find existing plugins, browse community ones on DSH Plugin Hub. - Enable
str_replace_editoron demand — the bundled runtime includes it, butsdk-minimaldoes not mount it by default. Write aneditor.patch.ymlthat usesinsertto add the filesystem backend and editor back, then pass it viapatchesor persist it incordis.patch.yml. Expected: after the next start, the model can use the tool beyond the persistent shell.
# editor.patch.yml
- insert:
- id: fs-local
name: '@deepseek-ai/dsh-fs-local'
config:
cwd: !!js process.cwd()
- id: tool-str-replace-editor
name: '@deepseek-ai/dsh-tool-str-replace-editor'
Note: another profile is valid only if it includes @deepseek-ai/dsh-sdk-app or another JSON-RPC server entry; a missing server entry, an unresolvable plugin, or an invalid patch fails at startup rather than falling back to another composition.
Understanding the sdk-minimal profile
sdk-minimal inserts a full config tree over an empty root without dsh-base, so tools added to the base profile later never appear implicitly (source). Its defaults:
| Property | Value |
|---|---|
| System prompt | DSH_SYSTEM_PROMPT, else You are a helpful software engineer assistant. |
Model for minimal.py | --model, then DSH_MODEL, then deepseek-v4-flash |
| Model-facing tool | persistent bash on Linux/macOS, or pwsh on Windows |
| Shell timeout | 300 seconds |
| Runtime context and compaction | none |
| Session persistence | uncompressed JSONL under <dsh_home>/sessions |
The profile contains the SDK protocol, an environment-configured DeepSeek adapter, local execution, and persistence. Filesystem tools, settings, managed credentials, OTel telemetry, web tools, subagents, local instruction discovery, and compaction are all absent. It also pins danger-full-access, so the persistent shell can modify any path visible to the runtime — always use a disposable checkout or container.
Notes and common questions
~/.dshis never read: the SDK uses only thedsh_homeyou pass; that isolation is deliberate.- Permissions are broad: under
danger-full-accessthe shell can write any visible path, so isolate the environment. - Session logs are uncompressed: JSONL under
<dsh_home>/sessions; watch disk usage and privacy, as in Where DeepSeek Harness session history lives. - The Web UI is not in the SDK: for a browser app in a Python SDK deployment, run
dsh webagainst an explicitDSH_HOME;webis a standalone CLI app and cannot serve a Python SDK client. - Changing models or adding self-hosted services: adjust
providersand credentials, as in Configure DeepSeek Harness model providers.
Sources: Python SDK (official docs), dsh CLI README
FAQ
Installing the DeepSeek Harness Python SDK needs Python 3.10 or newer plus Git, then pip install deepseek-harness-sdk. The install bundles a matching native runtime wheel and the dsh command; normal SDK runs do not need system Node.js.
In DeepSeek Harness code, use DeepSeekHarness as a context manager with provider, model, cwd, dsh_home, and profile, then call harness.run(prompt, session_id=...) and read result.final_response. The SDK lazily starts an internal dsh --profile sdk-minimal process and reuses it until exit.
No: the DeepSeek Harness SDK and its bundled examples never silently read ~/.dsh; the dsh_home you pass is the only source, and it stores the generated sdk-minimal profile, installed plugins, and session logs under sessions/.
Initialize the DeepSeek Harness profile first, then install packages with dsh plugin --profile sdk-minimal add (this step needs pnpm). Persist config edits in $DSH_HOME/profiles/sdk-minimal/cordis.patch.yml, or pass patches from Python for one run.
The DeepSeek Harness sdk-minimal profile does not mount str_replace_editor in its default Cordis tree. To enable it, write an editor.patch.yml that inserts fs-local and tool-str-replace-editor, then pass it via the patches argument or persist it in cordis.patch.yml.
Related Terms
- deepseek-harness-sdk
- deepseek-harness-sdk is the official Python package of DeepSeek Harness; installing it also brings a matching native runtime wheel and the dsh command, and the DeepSeekHarness class drives a dsh profile from code.— DeepSeek Harness Documentation - Python SDK
- sdk-minimal
- sdk-minimal is the standalone minimal profile bundled with the SDK; it inserts a full config tree over an empty root without dsh-base, containing only the SDK protocol, an environment-configured DeepSeek adapter, local execution, and persistence.— DeepSeek Harness Documentation - Python SDK
- dsh_home
- dsh_home is an isolated DeepSeek Harness home directory holding profiles, installed plugins, credentials, settings, and session logs; the SDK uses only the home you pass and never reads ~/.dsh.— DeepSeek Harness Documentation - Python SDK
- patch
- A patch is a configuration overlay of DeepSeek Harness that inserts or changes entries in an existing config tree; in the SDK it is composed from the profile's persistent patch, the home patch, and any patches tuple passed at construction.— DeepSeek Harness Documentation - Python SDK
Sources
- DeepSeek Harness Documentation - Python SDK· deepseek-harness
- dsh CLI README· deepseek-ai