Depending on how sudo has been configured, it may overwrite most environment variables. In particular, it is likely that it overwrites
SSH_AUTH_SOCK, and it might overwrite
HOME. That's not something you can fix without changing the sudo configuration.
You can see the sudo configuration (and in particular which environment variables are preserved) by running
sudo -V as root. It is a feature that you cannot see the configuration as an unprivileged user.
It is possible that your system administrator has locked down your sudo permissions so that the script cannot use your ssh keys. This could be a security policy, and if it is implemented correctly, then by definition you cannot fix it by yourself, you will need your sysadmin to change the configuration.
It's difficult to know what is needed without knowing what the script does and what the sudo configuration is. Perhaps a
sudoers line like the following might help (it tells sudo to preserve the
SSH_AUTH_SOCK environment variable if the command to run is
If the script runs as a user who is neither you nor root, you will have to give that user permission to read your keys or access your agent.