If the batteries are AGM--it is safe. If vented lead acid--then there is hydrogen gas produced. This can be explosive and also toxic. Practically, many boats do put batteries in semi enclosed spaces like this--but not really the best practice.
Most large vessels have the batteries in the engine room--that is an enclosed space, but has some minimal ventilation. We had about 1200 amp hours of golf carts under the pilot house settee of the boat we took to Europe and back. This was over the engine room, and there were louvered doors on the companionway, as well as dorade vents.