<?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: Youssef Najjarine</title>
    <description>The latest articles on DEV Community by Youssef Najjarine (@youssefnajjarine).</description>
    <link>https://dev.to/youssefnajjarine</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3877533%2Fbbfc2da2-1485-4bde-ad8b-7bca92e389d5.jpeg</url>
      <title>DEV Community: Youssef Najjarine</title>
      <link>https://dev.to/youssefnajjarine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/youssefnajjarine"/>
    <language>en</language>
    <item>
      <title>Building a Zero-Dependency Security SDK in Python</title>
      <dc:creator>Youssef Najjarine</dc:creator>
      <pubDate>Mon, 13 Apr 2026 23:57:21 +0000</pubDate>
      <link>https://dev.to/youssefnajjarine/building-a-zero-dependency-security-sdk-in-python-3p5e</link>
      <guid>https://dev.to/youssefnajjarine/building-a-zero-dependency-security-sdk-in-python-3p5e</guid>
      <description>&lt;p&gt;When we set out to build a runtime security tool for AI applications, we made one rule: zero external dependencies. Only the Python standard library.&lt;/p&gt;

&lt;p&gt;It sounds limiting. It was. But for a security tool, it turned out to be exactly the right constraint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why zero dependencies?
&lt;/h2&gt;

&lt;p&gt;Every dependency you add is a package that could be compromised in a supply chain attack. This isn't theoretical — in 2024, the &lt;code&gt;litellm&lt;/code&gt; package on PyPI was compromised with credential-stealing malware. Over 47,000 downloads happened in a 46-minute window before it was caught.&lt;/p&gt;

&lt;p&gt;A security tool that introduces its own attack surface defeats the purpose. So we committed to &lt;code&gt;pip install diogenesis-sdk&lt;/code&gt; installing exactly one package with zero transitive dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we built
&lt;/h2&gt;

&lt;p&gt;Diogenesis is a behavioral immune system for AI applications. Instead of maintaining a database of known threats (like antivirus), it monitors what your application actually does at runtime and flags deviations from normal behavior.&lt;/p&gt;

&lt;p&gt;It intercepts four categories of runtime events:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Imports&lt;/strong&gt; — every module your application loads&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File system activity&lt;/strong&gt; — reads, writes, deletions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network connections&lt;/strong&gt; — all outbound calls with destination and payload size&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Subprocesses&lt;/strong&gt; — every spawned process and its arguments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quick start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;diogenesis_sdk&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;activate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;field_state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;threat_summary&lt;/span&gt;

&lt;span class="nf"&gt;activate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. Four agents start patrolling your application automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we learned from the standard library
&lt;/h2&gt;

&lt;p&gt;Building without dependencies forced us to dig deep into parts of the standard library that most Python developers never touch. Here's what we found useful:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;sys.meta_path&lt;/code&gt; for import interception
&lt;/h3&gt;

&lt;p&gt;Python's import system is surprisingly hookable. By inserting a custom finder into &lt;code&gt;sys.meta_path&lt;/code&gt;, you can intercept every &lt;code&gt;import&lt;/code&gt; statement before it executes. This is how we track which modules your application loads and detect "shadow imports" — modules being loaded that weren't part of the established baseline.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;os.scandir()&lt;/code&gt; for file monitoring
&lt;/h3&gt;

&lt;p&gt;Most people reach for &lt;code&gt;watchdog&lt;/code&gt; when they need file system monitoring. But &lt;code&gt;os.scandir()&lt;/code&gt; is fast, built-in, and gives you everything you need — file type, stats, and path information — without adding a dependency.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;socket&lt;/code&gt; module for network tracking
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;socket&lt;/code&gt; module's &lt;code&gt;getaddrinfo&lt;/code&gt; function lets you track outbound connections at a low level. We wrap this to log every network call your application makes, including destination and timing.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;subprocess.Popen&lt;/code&gt; wrapping
&lt;/h3&gt;

&lt;p&gt;By wrapping &lt;code&gt;subprocess.Popen&lt;/code&gt;, we capture every external process your application spawns. This catches things like an AI agent deciding to run shell commands it was never intended to run.&lt;/p&gt;

&lt;h2&gt;
  
  
  The behavioral approach
&lt;/h2&gt;

&lt;p&gt;The key insight behind Diogenesis is that you don't need to know every possible attack to detect one. You just need to know what "normal" looks like.&lt;/p&gt;

&lt;p&gt;Every module in your application gets a "voltage" score — a measure of how closely its current behavior matches its baseline. When voltage drops, something has changed. Maybe it's fine. Maybe it's an AI agent that just started importing &lt;code&gt;shutil&lt;/code&gt; when it's never done that before.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;diogenesis_sdk&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;activate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;field_state&lt;/span&gt;

&lt;span class="nf"&gt;activate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;field_state&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;modules&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;voltage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;voltage&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;voltage&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;WARNING: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; coherence low (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;voltage&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OK: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; stable at &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;voltage&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Five built-in threat patterns run automatically: data exfiltration, privilege escalation, shadow imports, resource abuse, and behavioral drift. Each triggers a graduated response — LOG, WARN, or ALERT — so you're not drowning in false positives.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tradeoffs
&lt;/h2&gt;

&lt;p&gt;Zero dependencies isn't free. Here's what we gave up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No &lt;code&gt;requests&lt;/code&gt; library&lt;/strong&gt; — all HTTP handling uses &lt;code&gt;urllib&lt;/code&gt; and &lt;code&gt;socket&lt;/code&gt; directly. It's uglier but it works.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No &lt;code&gt;numpy&lt;/code&gt; for statistical analysis&lt;/strong&gt; — the behavioral baseline and voltage calculations use pure Python math. It's slower, but for a monitoring tool running in the background, it's fast enough.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No &lt;code&gt;click&lt;/code&gt; or &lt;code&gt;argparse&lt;/code&gt; alternatives&lt;/strong&gt; — CLI tooling is minimal and hand-rolled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing without &lt;code&gt;pytest&lt;/code&gt;&lt;/strong&gt; — we use &lt;code&gt;unittest&lt;/code&gt; from the standard library. 104 tests, all passing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Would we make the same choice for a web app or a data pipeline? Probably not. But for a security tool that sits inside other people's applications, minimizing the footprint is the right call.&lt;/p&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;pip &lt;span class="nb"&gt;install &lt;/span&gt;diogenesis-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;104 tests. Python 3.8 through 3.13. MIT licensed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/AI-World-CEO/diogenesis-sdk" rel="noopener noreferrer"&gt;github.com/AI-World-CEO/diogenesis-sdk&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PyPI:&lt;/strong&gt; &lt;a href="https://pypi.org/project/diogenesis-sdk/" rel="noopener noreferrer"&gt;pypi.org/project/diogenesis-sdk&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://diogenicsecurity.com" rel="noopener noreferrer"&gt;diogenicsecurity.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you've built something with a zero-dependency constraint, I'd love to hear about your experience. What did you gain? What did you miss?&lt;/p&gt;

</description>
      <category>python</category>
      <category>security</category>
      <category>opensource</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
