Skip to content

Conversation

@Yashp002
Copy link
Contributor

@Yashp002 Yashp002 commented Jan 8, 2026

sys.remote_exec(pid, script_path) creates a temporary script with restrictive
permissions (typically 0o600). The target process must be able to read this
file, which fails in cross-user scenarios (e.g. sudo debugging).

Added documentation note with example showing how to os.chmod() the file to
0o644 (readable by group/other) before calling.

Addresses the PermissionError reported in #143511.

Co-authored-by: @RafaelWO


📚 Documentation preview 📚: https://cpython-previews--143575.org.readthedocs.build/

@RafaelWO
Copy link
Contributor

RafaelWO commented Jan 8, 2026

Wouldn't it make more sense to add this info to the remote debugging docs? 🤔

@Yashp002
Copy link
Contributor Author

Yashp002 commented Jan 8, 2026

@RafaelWO Well i figured sys.rst or sys.executable here is way more used or gone through by users on a daily basis? Sys.rst is more discoverable for users hitting the error.
We could go with keeping it in both too but this one's just more discoverable imo unless I'm heavily mistaken.

@StanFromIreland StanFromIreland changed the title gh-143511: Document sys.remote_exec permissions requirements [skip news] gh-143511: Document sys.remote_exec permissions requirements Jan 9, 2026
The temporary script file is created with restrictive permissions (typically
``0o600``). The target process must be able to read this file.

Callers should adjust permissions before calling, e.g.::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use latin abbreviations, see the devguide for more information.

Comment on lines 2016 to 2019
.. availability:: Unix, Windows.
.. versionadded:: 3.14

The temporary script file is created with restrictive permissions (typically
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the directives (availability, versionadded) should always be at the end of a member section. Hence, I would move them to the end (or your addition above).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the changes @RafaelWO, could you verify them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not at the end. versionadded should be the last section. You added your section afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@picnixz You mean even after the example I've provided?

Comment on lines +2022 to +2033
Callers should adjust permissions before calling, for example::

import os
import tempfile
import sys

with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
f.write("print('Hello from remote!')")
f.flush()
os.chmod(f.name, 0o644) # Readable by group/other
sys.remote_exec(pid, f.name)
os.unlink(f.name) # Cleanup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be put before the audit event descriptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants