diff --git a/tools/run_tests/jobset.py b/tools/run_tests/jobset.py
index 4fe77487f96ff35e7b8805244ced50dde2a4245a..3999537c40e4dfb02d5ae55f3b5c0a8008b7c64f 100755
--- a/tools/run_tests/jobset.py
+++ b/tools/run_tests/jobset.py
@@ -47,6 +47,12 @@ measure_cpu_costs = False
 _DEFAULT_MAX_JOBS = 16 * multiprocessing.cpu_count()
 _MAX_RESULT_SIZE = 8192
 
+def sanitized_environment(env):
+  sanitized = {}
+  for key, value in env.items():
+    sanitized[str(key).encode()] = str(value).encode()
+  return sanitized
+
 def platform_string():
   if platform.system() == 'Windows':
     return 'windows'
@@ -219,6 +225,7 @@ class Job(object):
     env = dict(os.environ)
     env.update(self._spec.environ)
     env.update(self._add_env)
+    env = sanitized_environment(env)
     self._start = time.time()
     cmdline = self._spec.cmdline
     if measure_cpu_costs: