跳到正文
DEV Community· HY LUO·· 2 小時前AI 評分52

AILatch 讓 Python 程式在原始碼保持磁碟加密時仍可執行

Keeping sensitive source encrypted on disk while still running Python code

AI 導讀

AILatch 讓 Python 原始碼在磁碟上保持加密,並只在 AILatch 程序內載入明文執行。加密模組仍可互相匯入,程式亦可透過執行時掛鈎使用一般 `open()` 和 `pathlib` 讀取;工具另提供受控明文檢視、加密備份及復原指令。

正文

HY LUO

AI coding tools need to read project files. Some source code should still stay out of the workspace in plaintext.

I built AILatch for that boundary: files stay encrypted on disk, while Python code can run with plaintext materialized only inside the AILatch process.

The basic flow is:

pip install ailatch

ailatch lock secret.py
cat secret.py          # ordinary file reads see ciphertext
ailatch run secret.py  # run the program without restoring plaintext

ailatch run decrypts the entry file in memory and keeps the working-tree file encrypted. Encrypted Python modules can still import each other, and application code can use normal open() and pathlib reads through the runtime hooks.

When I need to inspect or edit a locked file, AILatch provides a controlled plaintext view:

ailatch open .
ailatch show secret.py

The project also includes encrypted backups and recovery commands:

ailatch lock secret.py --recovery
ailatch restore secret.py
ailatch recover secret.py

This is aimed at filesystem-level reads by AI tools and ordinary file utilities. It does not claim to stop a privileged local attacker who can inspect process memory or persuade a user to decrypt a file. Stronger isolation still requires operating-system permissions, process isolation, and careful credential handling.

AILatch currently targets Python 3.11+ and is primarily tested on Windows and macOS.

Repository and full command reference: github.com/lo2589/AILatch

Tags: #opensource #python #security #ai

來源:DEV Community · dev.to