pyrasite
Tools for injecting arbitrary code into running Python processes.
- homepage:
- documentation:
- download:
- source:
- issues:
Requirements
gdb (version 7.3+)
A Linux system whose ptrace policy allows attaching to the target process. See ptrace_scope below.
Installation
pipx install pyrasite
or, for the optional memory viewer:
pip install "pyrasite[memory-viewer]"
Compatibility
Pyrasite runs on CPython 3.9 through 3.15. Injection works between versions as well, so you can run Pyrasite under one Python and inject into a process running another. Both the pyrasite client and the target process must be CPython.
ptrace_scope
Recent Linux distributions restrict ptrace so that a process may only be attached to by its ancestors. If /proc/sys/kernel/yama/ptrace_scope is non-zero you will see a warning. You can either allow attaching globally:
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
or let the target process opt in by calling prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY). On Fedora, SELinux may also need:
sudo setsebool -P deny_ptrace=off
For multi-threaded programs pyrasite queues the payload with Py_AddPendingCall so that it runs on a thread that already holds the GIL. If the target is blocked in C and never executes Python bytecode, use --inject-method direct instead.
Usage
pyrasite <pid> hello.py
pyrasite <pid> - <<'EOF'
import sys
print(sys.version)
EOF
pyrasite <pid> <(echo 'print("hello")')
The payload is read by the pyrasite process and embedded in the gdb command, so the target does not need read access to the payload file. This also means pipes and process substitution work. Standard payloads can be selected by name (see pyrasite --list-payloads).
Remote and container use
To inject into a process on another host, run pyrasite there over SSH:
ssh host pyrasite <pid> - < payload.py ssh -t host pyrasite-shell <pid>
When the target is in a different container and must connect back to a different address, choose the listening address, the address advertised to the target, and optionally a fixed port:
pyrasite-shell <pid> --bind-host 0.0.0.0 \
--connect-host 10.0.0.5 --port 9001
The reverse shell socket has no authentication. Binding it to a non-loopback address lets anyone who can reach that address execute code in the target, so only do this on a trusted network or through an SSH tunnel.
Testing
pip install -e ".[dev]" pytest ruff check . ruff format --check .
To run the suite against every supported interpreter with uv:
uv python install 3.9 3.10 3.11 3.12 3.13 3.14 3.15 tox
To test injecting from one interpreter into all of the others, set PYRASITE_TEST_INTERPRETERS to a colon-separated list of interpreter paths before running pytest.
pyrasite-gui
The graphical interface is maintained separately at https://github.com/lmacken/pyrasite-gui.
Licenses
Code
Logo
Metadata
Release files for pyrasite 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyrasite-2.3.0.tar.gz | 58.0 kB | With provenance | Details for pyrasite-2.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyrasite-2.3.0-py3-none-any.whl | Python 3 | none | any | Details for pyrasite-2.3.0-py3-none-any.whl |
Total release size: 113.1 kB
Release files / pyrasite-2.3.0.tar.gz
| Download URL | pyrasite-2.3.0.tar.gz |
|---|---|
| Size | 58.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a9b12c2a227d1d25bc698f816355021d01d273a35db4f40fd47949c40a6c40f
|
|
BLAKE2b-256 checksum How to use checksums |
d6a83443bd550c3eb91ebacea86a5b48d61d060f86a8c70e8702c7bc68c9a483
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logRelease files / pyrasite-2.3.0-py3-none-any.whl
| Download URL | pyrasite-2.3.0-py3-none-any.whl |
|---|---|
| Size | 55.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2f06c99d8c4f88c8ddb276349d96b39d3238930f00c238573b7eec94a63f58a
|
|
BLAKE2b-256 checksum How to use checksums |
82d9e961f87f73f9c52fe3c228c0cd0530a5f89567310a0e7a95a32915cee7f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logSecurity for pyrasite 2.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyrasite-2.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.