I was thinking about this, if I have already done sudo in a shell & its authentication is active for a bit then any shell script I run (source) can potentially do a sudo and elevate status.
But for an attacker that convinced you to run some malicious shell commands (e.g. `curl ...| sh` or copy/pasting more than you bargained for) that's only a minor inconvenience; next time you sudo, they're root anyway.
//Edit
Also, an attacker aiming for root is a red herring. One compromised account can already be bad enough - why would they need root on your private computer when they already stole your password database, keylogged your master password and created an off-site backup of your home dir?
its been a few days but thanks for response. My concern was not a random attacker but the stuff I run after git clone from github, without much thought, I might add. it is possible for hacker to hide malicious code in a innocent looking git repo for some hot new project. wait for some people to give root access inside their home or better yet office lan & add a cronjob to steal stuff nightly with a LLMs help?
In any case safest route is to always do a new shell (or a docker vm) for fun activities.