Sequoia osascript -e yields "execution error: Not authorised to send Apple events to System Events. (-1743)"

Can the following very special case be made work under Sequoia - and of course, how?:

# Tell applications in the target user's session to quit gracefully
sudo launchctl asuser "$USER_ID" osascript -e '
	tell application "System Events"
		launch
		set appList to name of every application process whose background only is false
		repeat with appName in appList
			try
				tell application appName to quit
			end try
		end repeat
		log out
	end tell
'

This is an attempt to more gracefully log users out, instead of brute force killing their loginwindow process or doing

launchctl bootout user/"$(id -u "$user")"

Thanks!