Agent and tool serialisation is handled by src/smolagents/serialization.py. The SafeSerializer class provides a prefix-based wire format for passing Python objects in and out of remote execution sandboxes:
safe:<json>— JSON-safe encoding that handles common Python types (dicts, lists, tuples, sets, bytes, complex numbers, PIL Images, numpy arrays, dataclasses, datetime types, Path, Decimal).pickle:<base64>— pickle fallback, only used whenallow_pickle=Trueis explicitly set.
When allow_pickle=False (the default in all remote executors), any object that cannot be safely JSON-encoded raises a SerializationError rather than silently falling back to pickle. The SafeSerializer deserialiser code is injected verbatim into the remote kernel via get_deserializer_code() so it runs without needing smolagents installed in the sandbox.
src/smolagents/serialization.pysrc/smolagents/remote_executors.py