Yes, you can... there are several ways to do it.
Drill a hole in the back wall of the box and use a bulkhead to secure it in place. This is how the glass holes boxes work.
If it's just a 3-sided box (i.e. no back wall), then you'd have to adhere it to the glass. Aquarium silicone could be used, as could most aquarium safe epoxies. Some are easier to use/apply than others, some form stronger bonds than others.