<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/shadowing-the-standard-library-h4ru7robk" -->

---
title: Shadowing the Standard Library | daily.dev
description: An analysis of how dynamic-language runtimes handle putting the current or script directory on the module search path, prompted by a reported attack where a...
canonical: https://daily.dev/posts/shadowing-the-standard-library-h4ru7robk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Shadowing the Standard Library | daily.dev
og:description: An analysis of how dynamic-language runtimes handle putting the current or script directory on the module search path, prompted by a reported attack where a...
og:url: https://daily.dev/posts/shadowing-the-standard-library-h4ru7robk
og:image: https://api.daily.dev/og/posts/h4Ru7roBK.png
og:image:alt: Shadowing the Standard Library
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Shadowing the Standard Library

**[Andrew Nesbitt](https://daily.dev/sources/nesbitt-io)** · 7 min read · 1 upvotes · 0 comments

## Summary

An analysis of how dynamic-language runtimes handle putting the current or script directory on the module search path, prompted by a reported attack where a malicious struct.py shadowed Python's real struct module inside a coding agent's extracted archive. Ruby (1.9.2, 2010) and Perl (5.26, 2017, tied to CVE-2016-1238) removed the current directory from their load paths; Node, Java, Deno, and Julia never exposed the standard library to shadowing by design; PHP and Python still place the ambient directory first, ahead of the standard library, making stdlib modules shadowable. Python offers -I (3.4) and the narrower -P / PYTHONSAFEPATH (3.11) to disable the unsafe default, though a draft PEP to make safe-path the default has not landed. The piece argues that coding agents extracting archives and running helper scripts inside them recreate exactly the untrusted-cwd scenario that motivated Perl's and Ruby's fixes decades ago.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nesbitt.io/2026/09/15/shadowing-the-standard-library.html>

## Questions this post answers

### Why does Python's sys.path let a file named struct.py in my working directory override the real struct module?

Python prepends the script's directory as sys.path[0] when running a file (or the working directory for -m and -c), placing it ahead of the standard library on the module search path. Since struct is a plain .py wrapper resolved by PathFinder rather than a frozen or built-in module, a local struct.py is imported instead of the real one, silently intercepting anything that does import struct.

_Developers hardening agent sandboxes against import shadowing can track runtime security nuances like this on daily.dev._

### How do I stop Python from importing malicious local files instead of standard library modules?

Run the interpreter with -I (isolated mode, added in Python 3.4) or the narrower -P flag / PYTHONSAFEPATH environment variable (added in Python 3.11). Isolated mode suppresses sys.path[0], user site-packages, and all PYTHON* environment variables, while -P only drops the sys.path[0] entry and leaves the rest of the environment intact.

_Teams securing Python-based coding agents can follow this kind of hardening guidance via daily.dev._

### Why did Perl remove the current directory from @INC but Python still hasn't made safe-path the default?

Perl removed dot from the end of @INC in version 5.26.0 (May 2017) after CVE-2016-1238, reported by cPanel, showed a script that cd's to /tmp and loads an optional module could execute an attacker's file left there; Perl offered PERL_USE_UNSAFE_INC=1 as a transition escape hatch. Python's equivalent tracker issue, bpo-13475, was opened in November 2011, and a draft PEP proposing safe-path as the default (citing Perl 5.26 as precedent) still sits unmerged in a personal repository.

_Anyone weighing language runtime security trade-offs can keep tabs on proposals like this through daily.dev._

## Similar posts on daily.dev

- [Unbundling the standard library](https://daily.dev/posts/unbundling-the-standard-library-riniarrpi) · Andrew Nesbitt · 0 upvotes · 0 comments
- [One namespace to namespace them all \(Python Language Summit 2026\)](https://daily.dev/posts/one-namespace-to-namespace-them-all-python-language-summit-2026--zl2wui3x5) · Python Insider · 6 upvotes · 0 comments
- [The C\+\+ Standard Library Has Been Walking Itself Back for Fifteen Years, and the Receipts Are Public](https://daily.dev/posts/the-c-standard-library-has-been-walking-itself-back-for-fifteen-years-and-the-receipts-are-public-tdkysrrko) · Lobsters · 6 upvotes · 1 comments
- [Ruby, Rails & AI Daily — September 10, 2026" description: "A critical Active Storage RCE is now under active exploitation, ZJIT learns to inline GC allocations, and Google, Anthropic, and OpenAI all s](https://daily.dev/posts/ruby-rails-ai-daily-september-10-2026-description-a-critical-active-storage-rce-is-now-unde-xetkjqgtn) · Ruby Flow · 2 upvotes · 0 comments

---

Tags: [#security](https://daily.dev/tags/security), [#python](https://daily.dev/tags/python), [#ai-agents](https://daily.dev/tags/ai-agents), [#perl](https://daily.dev/tags/perl)

[View this post on daily.dev](https://daily.dev/posts/shadowing-the-standard-library-h4ru7robk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Shadowing the Standard Library","url":"https://daily.dev/posts/shadowing-the-standard-library-h4ru7robk","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/shadowing-the-standard-library-h4ru7robk"},"datePublished":"2026-09-15T09:49:33.238Z","dateModified":"2026-09-15T09:49:57.273Z","description":"An analysis of how dynamic-language runtimes handle putting the current or script directory on the module search path, prompted by a reported attack where a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/416572ca2b211e96c4c4b92af22d1ec7?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/416572ca2b211e96c4c4b92af22d1ec7?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Andrew Nesbitt","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Andrew Nesbitt","logo":"https://media.daily.dev/image/upload/logos/placeholder.jpg","url":"https://daily.dev/sources/nesbitt-io"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/shadowing-the-standard-library-h4ru7robk","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"security,python,ai-agents,perl","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Andrew Nesbitt","item":"https://daily.dev/sources/nesbitt-io"},{"@type":"ListItem","position":3,"name":"Shadowing the Standard Library"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/shadowing-the-standard-library-h4ru7robk#faq","mainEntity":[{"@type":"Question","name":"Why does Python's sys.path let a file named struct.py in my working directory override the real struct module?","acceptedAnswer":{"@type":"Answer","text":"Python prepends the script's directory as sys.path[0] when running a file (or the working directory for -m and -c), placing it ahead of the standard library on the module search path. Since struct is a plain .py wrapper resolved by PathFinder rather than a frozen or built-in module, a local struct.py is imported instead of the real one, silently intercepting anything that does import struct. Developers hardening agent sandboxes against import shadowing can track runtime security nuances like this on daily.dev."}},{"@type":"Question","name":"How do I stop Python from importing malicious local files instead of standard library modules?","acceptedAnswer":{"@type":"Answer","text":"Run the interpreter with -I (isolated mode, added in Python 3.4) or the narrower -P flag / PYTHONSAFEPATH environment variable (added in Python 3.11). Isolated mode suppresses sys.path[0], user site-packages, and all PYTHON* environment variables, while -P only drops the sys.path[0] entry and leaves the rest of the environment intact. Teams securing Python-based coding agents can follow this kind of hardening guidance via daily.dev."}},{"@type":"Question","name":"Why did Perl remove the current directory from @INC but Python still hasn't made safe-path the default?","acceptedAnswer":{"@type":"Answer","text":"Perl removed dot from the end of @INC in version 5.26.0 (May 2017) after CVE-2016-1238, reported by cPanel, showed a script that cd's to /tmp and loads an optional module could execute an attacker's file left there; Perl offered PERL_USE_UNSAFE_INC=1 as a transition escape hatch. Python's equivalent tracker issue, bpo-13475, was opened in November 2011, and a draft PEP proposing safe-path as the default (citing Perl 5.26 as precedent) still sits unmerged in a personal repository. Anyone weighing language runtime security trade-offs can keep tabs on proposals like this through daily.dev."}}]}
```

