How should I go about trying to script this?

Hey, guys so I would like any tips or suggestions on how to script square box extrusions to fill the mass while keeping the boxes rectilinear and taking the form of inside the mass. Almost like the Serpentine by BIG, but instead, it is a mass with vertical extrusions and it is


closed.