Is it possible to access yoroi private keys from the outside? For example, to write a script that does something with them?
Yoroi doesn't need to be involved. You can access your keys using the cardano-wallet suite of tools. You just need your seed phrase.
Yoroi and other wallets are just interfaces to the blockchain. The private keys on the chain are the same. Using the command line tools developed my IOG is basically what the wallets are doing behind the scenes.