We are running an Azure cloud service. We have an instance of Scalyr agent installed on the box to capture the logs. Every few days/weeks, the scalyr agent gets automatically removed from the instances. We believe this happens when windows automatically patches the boxes. Is there a way to prevent this from happening?
Cloud Services are the old, legacy solution , I would recommend you move away from that.
The issue you are having is due to you using cloud services, this is a PaaS solution where whatever you want to run on the VM is supposed to be part of your application bundle you deploy with the cloud service. Manually installing things on the cloud service VM's is not supported and you will see the issue you have observed.
You can see this from the docs here:
If you want a VM you can manually updated then you want to look at using IaaS virtual machines (and use the ARM version, not classic).