What the agent does
PyCrypto 2.6.1 is the release most lockfiles still name. PyPI lists two advisories against it, CVE-2013-7459 and CVE-2018-6594, and names no fixed version for either. It also no longer runs. The agent's first step is to show that on the Python the project targets, since the failure mode depends on the machine. Without a C compiler the install stops at configure: error: no acceptable C compiler found in $PATH. With one, the build succeeds on Python 3.8, 3.11 and 3.12, and then from Crypto.PublicKey import RSA raises a SyntaxError at line 585 of the installed RSA.py, which reads except ValueError, IndexError:. The source distribution is Python 2 code that relied on a conversion step at build time, and current build tools no longer run that step.
Next the agent maps what the project uses, which is usually far less than the whole library. In a library like thisbejim/Pyrebase the only import is from Crypto.PublicKey import RSA in pyrebase/pyrebase.py, and the only call is in create_custom_token: RSA.importKey(...) on the service account's PKCS#8 private key, whose result is handed to python_jwt.generate_jwt(payload, private_key, "RS256", exp). Reading the packaging files turns up the more interesting fact. requirements.txt pins pycrypto==2.6.1, but setup.py already lists pycryptodome==3.4.3 in install_requires. Someone started this migration and finished half of it. A user who installs the package through setup.py gets one library; a contributor who follows DEV.md and runs pip install -r requirements.txt gets the other.
The half that was done does not hold up either. pycryptodome==3.4.3 builds on Python 3.12 and then fails to import with SyntaxError: invalid hexadecimal literal. So the change is not to copy the setup.py line into requirements.txt. The agent picks the newest PyCryptodome that supports the project's Python floor (the current release requires Python 3.9 or newer, and an older interpreter resolves to an earlier one), writes the same specifier in both files, and removes pycrypto. Both distributions install a top-level package named Crypto, so it builds a fresh environment for the check instead of installing one over the other.
Then it exercises the one code path. The project's test suite cannot run in a sandbox, because it needs a real Firebase project and a service account file, so the agent writes a focused check: generate an RSA key, export it as PKCS#8, import it the way create_custom_token does, and sign a token with python_jwt. With PyCryptodome that produces a three-part RS256 token. It also tries the neighbouring calls a migration can trip on and reports what it finds. python_jwt.verify_jwt fails with module 'Crypto.PublicKey.RSA' has no attribute '_RSAobj', because that version of the JWT library reaches for a PyCrypto-only class. Pyrebase never verifies tokens, so the port is unaffected, but an application that used the same pair to verify would be.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Replace PyCrypto with PyCryptodome in this Python project. Read every dependency file (requirements*.txt, setup.py, setup.cfg, pyproject.toml, lockfiles) and report where they disagree about pycrypto or pycryptodome. Find every import from the Crypto package and list each class and function used with its arguments. In a clean environment on the project's target Python, try to install and import the pinned PyCrypto and record the exact error; if no compiler is present, install one and try again so both failures are recorded. Choose one PyCryptodome version that imports on every Python version the project supports and write the same requirement in every dependency file; remove pycrypto everywhere. Never install both in one environment. Port any call PyCryptodome dropped or changed (AES.new without a mode or IV, key.encrypt, key.sign, key.decrypt, Random.OSRNG, long_to_bytes imports) and list each one. If the test suite needs external credentials, do not run it; write a small check that drives each crypto code path with a generated key and include its output. Also test any third-party library that receives a key object from this code. Report other pinned packages that fail to import on the target Python, but do not change them. Open a pull request with the errors before and the check output after.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
A pull request that changes one line in requirements.txt and one in setup.py and touches no application code, because RSA.importKey still exists in PyCryptodome as an alias of import_key. The description quotes the two PyCrypto failures and the one from the stale PyCryptodome pin, shows the output of the signing check, and states which Python versions the chosen version was imported on.
A reviewer looks hardest at the version choice. A library with users on old interpreters cannot simply take the newest release, and an exact pin in install_requires, which is this project's habit, forces that choice on everyone who installs it. The agent keeps the project's pinning style and says so; loosening it to a range is a one-line suggestion in the description.
The description ends with what is still broken, kept apart from what was fixed. On Python 3.12 the package does not import after this change, for a reason unrelated to cryptography: the pinned requests==2.11.1 fails with No module named 'urllib3'. The security alert that started the run is resolved, and the next pin to update is named.
Run it on every Dependabot alert for pycrypto
A security alert is a good trigger for this job, because the advisory has no patched version to bump to and so no automatic pull request ever arrives. GitHub can deliver a dependabot_alert webhook, but it signs its own deliveries and cannot send a custom Authorization header, so it cannot call Rush directly. Put a small handler on your server that verifies GitHub's signature, ignores alerts for other packages, and forwards the payload.
On the Rush side, add an automation to the Project with a webhook trigger and the prompt above. The handler calls the trigger's URL with the trigger's secret as a bearer token in the Authorization header. It also sends the trigger an Idempotency-Key header set to the alert's id, so that a redelivery from GitHub starts nothing new. The payload, up to 64 KB, arrives after the prompt as event text, and the saved prompt stays the only instruction.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
Whether a broken native package can be installed depends on the machine, and a laptop is the worst place to find out. One engineer has a compiler and gets a syntax error at import; another has none and gets a configure error; a third has a five-year-old virtual environment where everything still works. The agent starts from a clean sandbox, installs a compiler when the first attempt needs one, and records both failures, so the pull request describes what a new contributor or a fresh CI image will meet.
A clean environment also settles the namespace problem. Because both distributions unpack into Crypto, an environment that ever had PyCrypto can keep stale files after the switch and pass or fail for the wrong reason. A sandbox created for the task never had the old package, and the signing check it runs is against exactly the files a fresh install produces.
Frequently asked questions
Is PyCryptodome a drop-in replacement for PyCrypto?
For most code, yes: it keeps the Crypto package name and most of the API. A few things were removed on purpose. key.encrypt and key.sign on RSA keys raise NotImplementedError and point you to Crypto.Cipher and Crypto.Signature, and AES.new requires an explicit mode. The agent searches for those calls and ports each one.
Should I use pycryptodome or pycryptodomex?
They are the same code under two names. pycryptodome installs as Crypto and replaces PyCrypto, so imports stay as they are. pycryptodomex installs as Cryptodome and can coexist with an old PyCrypto, at the cost of rewriting every import. If nothing else in your environment still needs PyCrypto, the first is the smaller change.
Why does pip install pycrypto fail on my machine but not on a colleague's?
It has only a source distribution, so installing it compiles C code and needs a compiler and Python headers. With those present it installs, and then fails on import under Python 3 with a syntax error.
Will other libraries that use my keys still work?
Usually, but check each one. Libraries written against PyCrypto sometimes test for its internal classes. The JWT library pinned in this project can sign with a PyCryptodome key and cannot verify with one. The prompt asks the agent to drive every third-party call that receives a key, so a gap like that is in the pull request and not in production.
More jobs like this: Fix a bug from an alert
- Fix openai.ChatCompletion Errors by Migrating to the v1 Client (OpenAI Python SDK)
- Trim Message History in a LangGraph Agent (LangGraph)
- Add Connection Pooling to a GORM App (GORM)
- Add Connection Pooling Limits to a Prisma App on Serverless (Prisma)
- Add Database Indexes to a SQLModel App With Alembic (SQLModel)
- Add Graceful Shutdown to Services Running on Kubernetes (Kubernetes)