Skip to content

About

把 Agent 任务交给自己的 SSH 服务器,在 Docker 中隔离执行,支持文件传输与日志跟踪。

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

dsh-task2docker-studio

English · 简体中文

Task-to-Docker studio plugin for DeepSeek Harness: offload compute from a weak or security-constrained host onto servers you already control. The host stays a controller — it registers a runner, sends a task, and follows the result.

Vendor-neutral. A runner is any machine you can reach over SSH: a cloud server, a GPU box, a cluster entry node. No provider SDK or third-party API key is required.

Built for two scenarios:

  • The host is weaker than the target. Run models, builds, or batch jobs on a server that can handle them.
  • Separate experimental work from the controller. Use a hardened container on the runner, or explicitly choose full-trust native execution.

A task runs as a detached hardened container when an image is set, or backgrounded on the remote host otherwise.

Security defaults

  • Every model-visible t2d_* call requires one-shot user approval. Rejected, cancelled, and unavailable decisions fail closed.
  • SSH host-key checking defaults to strict; unknown host keys are rejected.
  • Password auth uses deployment-owned secretRef aliases bound to SSH host allowlists. Models cannot provide environment variable names or file paths.
  • SSH/SCP operations observe cancellation, wait for owned processes to exit, and cap captured output at 4 MiB per stream.
  • Runner/job state uses atomic owner-only writes. Raw task commands are not persisted.
  • Containers use a read-only root filesystem, bounded /tmp, no capabilities, no new privileges, a non-root user, no network by default, and PID/memory/CPU limits.
  • Native runs use a random owner-only log directory, a separate process group, and a recorded exit code.

What it gives the agent

Tool Purpose
t2d_register_runner Register a runner with key auth or a deployment-bound secretRef
t2d_list_runners List registered runners and secret aliases
t2d_remove_runner Forget a runner
t2d_copy_to Push a local file or directory over scp
t2d_copy_from Pull artifacts back over scp
t2d_run Dispatch a command as a tracked container or native job
t2d_status Poll state and exit code
t2d_logs Tail output or follow it for a bounded window
t2d_stop Stop the job and remove its container or private native logs

The bundled task2docker-studio skill teaches the loop: list → register → copy_to → run → status → logs → copy_from → stop.

Install (DeepSeek Harness)

dsh plugin --profile web add https://github.com/CarryChang/dsh-task2docker-studio

Install from a local checkout

Clone and build the plugin first:

git clone https://github.com/CarryChang/dsh-task2docker-studio.git
cd dsh-task2docker-studio
pnpm install
pnpm run build

Run the following from the DSH source root, replacing <path> with the plugin directory:

pnpm dsh plugin --profile web add <path>

If the DSH CLI is installed, you can also use dsh plugin --profile web add <path>. A local install links the directory; after changing the source, run pnpm run build again.

The DSH plugin requires the approval service. A profile without an approval answerer fails closed for every tool call.

Configure

Register key-authenticated runners live:

> I have a server at 203.0.113.10, root with public-key auth. Register it as gpu-box.

Or declare runners and trusted secrets in cordis.yml:

- id: task2docker
  name: dsh-task2docker-studio
  config:
    stateDir: ''                 # default ~/.dsh-task2docker
    sshTimeoutSec: 60
    sshHostKeyPolicy: strict     # strict or accept-new
    secrets:
      isolated-pw:
        env: ISOLATED_PW         # exactly one of env or file
        # file: /run/secrets/isolated_pw
        hosts: [203.0.113.20]    # required host allowlist
    docker:
      network: none              # none or bridge
      pidsLimit: 256
      memory: 2g
      cpus: 2
      user: '65534:65534'
      tmpfsSize: 256m
    runners:
      - name: gpu-box
        host: 203.0.113.10
        user: root
        auth: key
        defaultImage: pytorch:2.4
      - name: isolated
        host: 203.0.113.20
        auth: sshpass
        secretRef: isolated-pw

Credentials

  • Key / agent auth stores no secret and is the recommended path.
  • Password auth stores only the alias. The alias resolves to an environment variable or regular owner-only file at call time and is rejected for any host outside its allowlist.
  • sshpass must be installed on the controller for password auth. The password is passed through a temporary 0600 file that is removed after the SSH/SCP process exits.
  • Strict host-key checking requires the runner key to exist in the controller's known_hosts before use. Establish it through the normal SSH trust process.

Container policy

Container runs always apply:

--read-only
--cap-drop=ALL
--security-opt=no-new-privileges
--init
--tmpfs /tmp:rw,noexec,nosuid,size=<configured>
--user <non-root numeric UID[:GID]>
--entrypoint bash
--network <none|bridge>
--pids-limit <configured>
--memory <configured>
--cpus <configured>

Mounts are read-only by default. Set readonly: false only when the task must write through a staged host directory. Docker socket, root, /dev, /proc, /sys, /run, and /var/run host mounts are blocked. The runner also resolves each source with realpath before launch, so ./// aliases and symlinks to blocked control paths are rejected.

This is stronger isolation, not a dedicated hostile-code sandbox. Containers share the runner kernel, and bridge networking permits external traffic. Use native mode only when full host access is required.

Try it

> Upload ./src to gpu-box at /data/src, mount it read-only, and run python /workspace/train.py in pytorch:2.4.
> Show the job status and follow its log for 60 seconds.
> Pull /data/out back to ./out when it finishes.

The normal file flow is:

  1. t2d_copy_to stages code or data on the runner.
  2. t2d_run mounts the staged path into the container.
  3. t2d_status and t2d_logs observe the job.
  4. t2d_copy_from retrieves artifacts.

State and failure behavior

  • runners.json and jobs.json live under stateDir and are written atomically with owner-only permissions on POSIX. On Windows, inherited ACLs are removed and only the current user is granted access.
  • jobs.json stores a non-sensitive launch summary, not the raw command.
  • Native jobs record PID, private log path, and exit-code file. A nonzero exit becomes FAILED; a missing exit record becomes UNKNOWN.
  • Stopping a native job terminates its process group and removes its private log directory. Stopping a container removes it.
  • A cancelled SSH/SCP call settles only after the owned child process exits.
  • Legacy passwordEnv / passwordFile runner records are rejected. Re-register them with a configured secretRef.

Use it as a standalone Agent Skill

The open Agent Skill lives under skills/dsh-task2docker-studio/. It includes a standard-library-only CLI and can run without DSH:

cd skills/dsh-task2docker-studio
node scripts/t2d.mjs register --name gpu-box --host 203.0.113.10 --user root --image pytorch:2.4
node scripts/t2d.mjs run --runner gpu-box --command "python train.py"
node scripts/t2d.mjs status --job <id>
node scripts/t2d.mjs logs --job <id> --tail 80 --follow 60
node scripts/t2d.mjs stop --job <id>

The standalone CLI supports key/agent authentication only. Password auth requires DSH's deployment-owned secret configuration. Use the standalone CLI only in a trusted local agent context; it does not provide DSH's approval service.

The portable runtime is generated from the DSH-free backend by scripts/build-portable.mjs. src/backend/*.ts remains the source of truth.

Architecture

src/
  index.ts             plugin entry: Config + approval + skill + 9 tools
  skill.ts             embedded dispatch methodology
  backend/
    types.ts           Runner, SecretSource, JobRecord, SshClient, DockerOptions
    permissions.ts     owner-only POSIX modes and Windows ACL replacement
    ssh.ts             SSH/SCP argv, Docker/native commands, cancellation, output limits
    registry.ts        validation, secret aliases, atomic state store
    engine.ts          register / copy / run / status / logs / stop
scripts/
  clean.mjs            removes generated outputs before every build
  smoke.ts             deterministic offline security smoke
  build-portable.mjs   generates the standalone runtime and rejects bare imports

Limitations

  • Runners must be SSH-reachable from the controller.
  • Container runs require Docker on the runner, an image containing bash, and realpath on the runner for mount preflight. Native runs require a POSIX remote shell and setsid, mktemp, nohup, and timeout for followed logs.
  • sshpass is required on the controller for password auth.
  • No GPU or device mapping is exposed. Use a preconfigured runner image and deployment-specific Docker setup when GPU access is required.
  • Returned logs are raw task output and may contain secrets; treat them as sensitive model-visible data.

Provenance and license

MIT licensed. v0.1 targeted OpenBayes / HyperAI GraphQL; v0.2 removed that coupling. v0.6 removes the retired generated GraphQL files from builds and releases and adds the security defaults above. Not affiliated with or endorsed by DeepSeek, Docker, or any cloud provider.

Development

pnpm run clean
pnpm run build   # clean -> tsc -> portable runtime
pnpm run test    # deterministic offline security smoke
pnpm run check   # clean -> typecheck -> smoke -> portable runtime -> CLI smoke

About

把 Agent 任务交给自己的 SSH 服务器,在 Docker 中隔离执行,支持文件传输与日志跟踪。

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages