Adding a node to run a script

So for example, I am trying to deliver a package that is locked using a relay switch.

Would I be able to have a node that would run and upload the script onto an Arduino?
like I would have a node that would subscribe to the topic of the position and if the position is the final position reached, it would simply compile the code onto the board and make the relay turn on? I am using the case of an Arduino as I know the GPIO pins are all occupied.

Is this possible, otherwise is there a simpler alternative? (while still keeping that “security” feature)

Edit: I think a more practical approach is to have a system set up which would simply communicate to the customer directly, such as having another raspberry pi to manage this service. The customer would simply receive an OTP directly to them when they make the request…