Get a good lawyer?
I mean it's pretty simple:
1. You beat the rap
2. You escape
3. You do the time
4. You do the time for whatever crimes you commit trying to escape as well--or get killed trying to escape.
5. Maybe you get sold into slavery instead of being put in prison. It may or may not be easier to escape as a slave than as a prisoner.
But, realistically, you guys are 4th level. You don't have any world-shattering powers yet so the jail is probably built to hold you pretty well. You might escape (some people manage it) but you probably won't. If every fourth level guy who wanted to escaped, there wouldn't be much law left.
If you're really innocent and the land is reasonably close to just, working within the law to get out is probably your best bet. If you're guilty and the land is incompetent or corrupt, finding some way to bribe or blackmail the judge is probably your best bet. If you're guilty in a just land or innocent and being railroaded/framed/etc then you'll have to take your chances and pick the best time to try and escape. Be patient though. Grabbing the guard's sword and running away may work in the short term, but it's not always your best bet.