There is, indeed, a way! No way has yet been found (at least that I've found) to generate them infallibly, though.
In a paper by Y. Murase, H. Matsubara, and Y. Higara, called "Automatic Making of Sokoban Puzzles", they explain exactly how one makes unique puzzles. While their algorithm isn't perfect (about half of the puzzles they generated aren't solvable), it offers a significant statistical advantage over other possible methods.
In essence, they rely on three basic templates which are applied over a basic template which statistically are likely to generate solvable situations. Then, they mark specific spaces as invalid for both goals and boxes.
Goals are generated first, as boxes' positions are restricted by the goals. Invalid positions for goals can be categorized by checking each direction; if there is no valid way to push a box into the goal from any direction, that position cannot be a goal.
Then, crates are marked. The majority of invalid crate positions are those in corners (positions bounded by two walls) and those against walls with no goal access. These invalid positions are re-evaluated after placing each crate to insure that, for instance, two crates aren't placed adjacently against a wall.
Then they literally run a solving algorithm on it and see if it works.
You can see a demonstration of this algorithm, called Autosokoban.