agent: Fix ENV sanitization, adding test for bad tag