<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: jie123108</title>
    <description>The latest articles on DEV Community by jie123108 (@jie123108).</description>
    <link>https://dev.to/jie123108</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4039803%2F97534f4f-ac21-4748-ade9-8ee6baf79e4b.png</url>
      <title>DEV Community: jie123108</title>
      <link>https://dev.to/jie123108</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jie123108"/>
    <language>en</language>
    <item>
      <title>I built SSH session middleware so AI agents can work behind jump hosts</title>
      <dc:creator>jie123108</dc:creator>
      <pubDate>Tue, 21 Jul 2026 12:13:30 +0000</pubDate>
      <link>https://dev.to/jie123108/i-built-ssh-session-middleware-so-ai-agents-can-work-behind-jump-hosts-4da0</link>
      <guid>https://dev.to/jie123108/i-built-ssh-session-middleware-so-ai-agents-can-work-behind-jump-hosts-4da0</guid>
      <description>&lt;p&gt;I build a lot with AI coding agents these days. Writing code, editing docs, poking at web pages — an agent can mostly handle it. The place it consistently falls apart is &lt;strong&gt;servers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Most of the machines I care about sit behind one or more bastion / jump hosts, with menus, OTP prompts, and the occasional legacy login flow. An agent can't just &lt;code&gt;ssh user@host&lt;/code&gt; its way in, so the automation breaks right at the boundary. And debugging is worse: I end up logging in by hand, copying a log down to my laptop, pasting it into the agent, getting back a list of steps, then going back to the server to run them. Over and over.&lt;/p&gt;

&lt;p&gt;So I built &lt;strong&gt;Shellink&lt;/strong&gt;: a local daemon that owns SSH and local PTY sessions, with one stable CLI (plus a TUI, a Web UI, and HTTP/WebSocket APIs) on top. The idea is a "session middleware" that both a human and an agent can drive.&lt;/p&gt;

&lt;p&gt;Repo (MIT): &lt;a href="https://github.com/jie123108/Shellink" rel="noopener noreferrer"&gt;https://github.com/jie123108/Shellink&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's an agent hopping through a jump host and working on the target server, entirely through the Shellink CLI:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F23wu4f5vc1h06cikyns0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F23wu4f5vc1h06cikyns0.gif" alt="An AI agent hops through a jump host and runs commands on the target server" width="720" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What it actually does
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SSH and custom command sessions.&lt;/strong&gt; Connect directly over SSH, or run any command/script inside a PTY.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-hop login via &lt;code&gt;command&lt;/code&gt; profiles.&lt;/strong&gt; For bastion menus / OTP / multi-level hops, you point a &lt;code&gt;command&lt;/code&gt;-type profile at an &lt;code&gt;expect&lt;/code&gt; (or &lt;code&gt;sshpass&lt;/code&gt;, or &lt;code&gt;ssh -J&lt;/code&gt;) script. Shellink itself does &lt;em&gt;not&lt;/em&gt; log in for you — it manages the session &lt;em&gt;after&lt;/em&gt; you're in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File transfer over the existing PTY, not SFTP.&lt;/strong&gt; Upload/download keep working through a multi-hop, expect-driven login where you have no direct SFTP/SCP endpoint. This is the feature I needed most; it's what killed the "copy the log down by hand" loop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A real session state machine.&lt;/strong&gt; &lt;code&gt;CONNECTING / OUTPUTTING / WAITING_INPUT / IDLE / DISCONNECTED&lt;/code&gt;, exposed as machine-readable output, so an agent can decide whether to run the next command, send input, wait, or hand off — instead of guessing from scraped text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AUTO vs MANUAL mode.&lt;/strong&gt; The agent works in AUTO; a human can grab the terminal for OTP entry or anything sensitive, then hand it back. Session I/O is retained as history for audit/replay.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An agent skill (&lt;code&gt;shellink-cli&lt;/code&gt;).&lt;/strong&gt; The agent just calls the CLI (stable &lt;code&gt;--json&lt;/code&gt; output) instead of reimplementing SSH/jump-host logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A quick taste of the CLI
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# create a profile without leaking credentials into shell history&lt;/span&gt;
shellink profile create &lt;span class="nt"&gt;--input&lt;/span&gt; - &lt;span class="nt"&gt;--json&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;JSON&lt;/span&gt;&lt;span class="sh"&gt;'
{"name":"local-shell","connectType":"command","command":"/bin/sh"}
&lt;/span&gt;&lt;span class="no"&gt;JSON

&lt;/span&gt;shellink session create &lt;span class="nt"&gt;--profile&lt;/span&gt; &amp;lt;profile-id&amp;gt; &lt;span class="nt"&gt;--json&lt;/span&gt;
shellink session &lt;span class="nb"&gt;exec&lt;/span&gt; &amp;lt;session-id&amp;gt; &lt;span class="nt"&gt;--command&lt;/span&gt; &lt;span class="s1"&gt;'uname -a'&lt;/span&gt; &lt;span class="nt"&gt;--json&lt;/span&gt;
shellink session download &amp;lt;session-id&amp;gt; &lt;span class="nt"&gt;--path&lt;/span&gt; /var/log/app.log &lt;span class="nt"&gt;--output&lt;/span&gt; ./app.log &lt;span class="nt"&gt;--json&lt;/span&gt;
shellink session close &amp;lt;session-id&amp;gt; &lt;span class="nt"&gt;--json&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The interesting technical bits
&lt;/h2&gt;

&lt;p&gt;The transfer-over-PTY part was the fun/hard one. When your only channel to a box is a PTY that went through two bastions and an &lt;code&gt;expect&lt;/code&gt; script, you don't get SFTP. So transfers are encoded over the same terminal stream and reassembled on the other side, which means the exact same code path works for a direct SSH box and a three-hop legacy one.&lt;/p&gt;

&lt;p&gt;The state machine matters more than it sounds. The difference between "the command finished" and "the shell is waiting for input" is what lets an agent act instead of sleep-and-hope. Shellink derives state from a quiet-period heuristic plus prompt detection and exposes it explicitly.&lt;/p&gt;

&lt;p&gt;Stack: TypeScript, Node 22, Fastify, &lt;code&gt;ssh2&lt;/code&gt;, &lt;code&gt;node-pty&lt;/code&gt;, SQLite (&lt;code&gt;better-sqlite3&lt;/code&gt; + Drizzle), MessagePack + Zod on the wire, Vue 3 + xterm.js for the Web UI. Single-file Bun binaries for macOS/Linux.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest limitations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It doesn't do the login for you.&lt;/strong&gt; Multi-hop / menus / OTP are your &lt;code&gt;expect&lt;/code&gt; (or ssh/sshpass) script; Shellink manages what happens after.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;command&lt;/code&gt; profiles run as the daemon user.&lt;/strong&gt; Only run trusted commands, and protect &lt;code&gt;SHELLINK_TOKEN&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Letting an agent touch production is genuinely risky.&lt;/strong&gt; I'd point it at read-only/inspection tasks, or non-prod, first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Windows yet&lt;/strong&gt; (macOS/Linux binaries only).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/jie123108/Shellink/main/install.sh &lt;span class="nt"&gt;-o&lt;/span&gt; /tmp/shellink-install.sh
&lt;span class="nb"&gt;cat&lt;/span&gt; /tmp/shellink-install.sh   &lt;span class="c"&gt;# read before you run it&lt;/span&gt;
sh /tmp/shellink-install.sh
shellink cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What I'd love feedback on
&lt;/h2&gt;

&lt;p&gt;If you live behind bastions: does the &lt;code&gt;command&lt;/code&gt; + &lt;code&gt;expect&lt;/code&gt; approach actually cover your login chain, or does your setup have something it wouldn't survive? And if you wire up agents: is the CLI/&lt;code&gt;--json&lt;/code&gt; surface enough, or what's missing?&lt;/p&gt;

&lt;p&gt;Repo again: &lt;a href="https://github.com/jie123108/Shellink" rel="noopener noreferrer"&gt;https://github.com/jie123108/Shellink&lt;/a&gt; — issues and PRs welcome.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
      <category>ai</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
