Implement with_compartment to enter compartments from Rust code.