Add a little “copy” button to the right of your code blocks. This extension is maintained by Executable Books.
pip install sphinx-copybutton
Then, add the extension to your
extensions = [ # ... "sphinx_copybutton", ]
Hovering on the code block above, you will see a copy button.