In jam , silicone works fine. or you can use this neat
black gooy stuff
Sometimes called mastic tape, sometimes called all kinds of things. It's a real mess to work with but it seals thing up nicely and you can set a layer on one surface and it won't smear around if you slip like silicone ( but it will stick and you will have to pop it loose
Regular foam can let fumes through to the passenger compartment.
Once you get the box on, have some more fun and get some of that 1/4" closedcell foam with double sided foil insulation and wrap the whole box with the stuff to insulate it from the engine compartment. It will help your ac temps a bunch