It's technically optional in most institutions, but not practically optional. For instance, a lot of labor can reduce your sentence, can give you better housing and can enable you to afford things on commissary you might need (e.g. phone time, hygiene products etc).