Is transformers safe?
- Python shell/command execution
- Python dynamic code execution
- Unsafe deserialization
What to do: Nothing here argues against installing it. Grant the capabilities it lists only if you expect the tool to need them.
transformers is a PyPI package analyzed by SkillTotal's deterministic static scanner. The scan found no malicious indicators, though 1 risky construct is reported for review. It can: dynamic code execution, filesystem read, filesystem write, install time execution, network egress and shell execution — capabilities are what the code can do, not a verdict on intent. Risk score 20/100 (low).
transformers-5.19.0 5.19.0
Automated static-analysis result. It can contain false positives and false negatives, and is not a claim about the intent of transformers's authors. Report a false positive.
Behavioral traits
How this component maps to the CSA agentic threat model. Descriptive — it never affects the risk score.
Findings (7)
It loads data with a format that can rebuild arbitrary objects (e.g. pickle, or unsafe YAML).
passages = pickle.load(passages_file)
self.index_id_to_db_id = pickle.load(metadata_file)
Why it matters: Feeding such a loader untrusted data can execute code hidden inside that data.
Fix: Deserialize untrusted data with a safe format/loader: JSON, or yaml.safe_load / Loader=SafeLoader. Reserve pickle/marshal for data you fully control.
The code turns strings into live code at runtime (eval / new Function / exec).
wrapped_encoder = Seq2SeqLMEncoderExportableModule(self.encoder).to(self.full_model.device).eval()
Seq2SeqLMDecoderExportableModuleWithStaticCache(
model=self.full_model,
max_static_cache_length=self.generation_config.cache_config.get("max_cache_len"),
batch_size=self.generation_config.cach …self.semantic_model = AutoModel.from_config(config.semantic_model_config).eval()
self.semantic_model = AutoModel.from_config(config.semantic_model_config).eval()
Why it matters: If those strings aren't fixed and trusted, they become a way to run arbitrary code.
Fix: Avoid evaluating dynamically constructed code; if unavoidable, ensure the input is a trusted constant and never derived from external data.
The Python build/install configuration runs code at install time.
cmdclass={"deps_table_update": DepsTableUpdateCommand},Why it matters: Code that runs during pip install is a common supply-chain execution point.
Fix: Verify the build hook performs only a legitimate build step and does not execute commands or reach the network during installation.
The component can run operating-system commands or spawn processes.
subprocess.run(
["ruff", "check", new_module_folder, tests_folder, model_init_file, "--fix"],
cwd=repo_path,
stdout=subprocess.DEVNULL,
)subprocess.run(
["ruff", "format", new_module_folder, tests_folder, model_init_file],
cwd=repo_path,
stdout=subprocess.DEVNULL,
)subprocess.run(
["python", "utils/check_doc_toc.py", "--fix_and_overwrite"], cwd=repo_path, stdout=subprocess.DEVNULL
)subprocess.run(["python", "utils/sort_auto_mappings.py"], cwd=repo_path, stdout=subprocess.DEVNULL)
subprocess.run(
["python", "utils/modular_model_converter.py", new_lowercase_name], cwd=repo_path, stdout=subprocess.DEVNULL
)ffmpeg_process = subprocess.Popen(ffmpeg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
with subprocess.Popen(ffmpeg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) as ffmpeg_process:
with subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE, bufsize=bufsize) as ffmpeg_process:
ffmpeg_devices = subprocess.run(command, text=True, stderr=subprocess.PIPE, encoding="utf-8")
subprocess.check_output(["ninja", "--version"])
Why it matters: Powerful and often legitimate — confirm the commands aren't built from untrusted input.
Fix: Confirm the command and its arguments are fully controlled and not derived from untrusted input; avoid shell=True.
The component reads files from disk.
long_description=open("README.md", "r", encoding="utf-8").read(),with open(audio, "rb") as audio_file:
with open(file_name, "r", encoding="utf-8") as f:
autofile = (repo_path / "src" / "transformers" / "models" / "auto" / "auto_mappings.py").read_text()
file = (repo_path / "src" / "transformers" / "models" / "auto" / filename).read_text()
with open(toc_file, "r", encoding="utf-8") as f:
with open(module_name, "r", encoding="utf-8") as file:
with open(original_test_path, "r", encoding="utf-8") as f:
with open(examples_path, encoding="utf-8") as f:
with open(json_file, encoding="utf-8") as reader:
with open(model, "rb") as f:
with open(self.original_tokenizer.vocab_file, "rb") as f:
with open(vocab_file, "rb") as f:
with open(vocab_file, "rb") as f:
with open(vocab_file, "rb") as f:
with open(
os.path.join(data_dir, self.train_file if filename is None else filename), "r", encoding="utf-8"
) as reader:with open(
os.path.join(data_dir, self.dev_file if filename is None else filename), "r", encoding="utf-8"
) as reader:with open(input_file, "r", encoding="utf-8-sig") as f:
with open(module_file, encoding="utf-8") as f:
with open(filename, encoding="utf-8") as f:
module_hash: str = hashlib.sha256(b"".join(bytes(f) + f.read_bytes() for f in module_files)).hexdigest()
source_files_hash.update(file_path.read_bytes())
with open(requirements, "r", encoding="utf-8") as f:
with open(json_path, encoding="utf-8") as f:
with open(json_file, encoding="utf-8") as reader:
Why it matters: Usually legitimate, but worth confirming it can't be steered into reading sensitive files.
Fix: Confirm which files are read and that paths cannot be influenced by untrusted input to reach sensitive locations.
The component writes or deletes files on disk.
shutil.rmtree(stale_egg_info)
with open(target, "w", encoding="utf-8", newline="\n") as f:
with open(file_name, "w", encoding="utf-8") as f:
with open(new_module_folder / f"modular_{new_lowercase_name}.py", "w", encoding="utf-8") as f:with open(new_module_folder / "__init__.py", "w", encoding="utf-8") as f:
with open(tests_folder / "__init__.py", "w", encoding="utf-8"):
with open(tests_folder / filename, "w", encoding="utf-8") as f:
with open(
repo_path / "docs" / "source" / "en" / "model_doc" / f"{new_lowercase_name}.md", "w", encoding="utf-8"
) as f:with open(filename, "w", encoding="utf-8") as f:
with open(json_file_path, "w", encoding="utf-8") as writer:
os.remove(file_name)
with open(output_prediction_file, "w", encoding="utf-8") as writer:
with open(output_nbest_file, "w", encoding="utf-8") as writer:
with open(output_null_log_odds_file, "w", encoding="utf-8") as writer:
with open(output_prediction_file, "w", encoding="utf-8") as writer:
with open(output_nbest_file, "w", encoding="utf-8") as writer:
with open(output_null_log_odds_file, "w", encoding="utf-8") as writer:
with open(json_file_path, "w", encoding="utf-8") as f:
shutil.copyfile(resolved_module_file, submodule_path / module_file)
shutil.copyfile(source_file, target_path)
shutil.copyfile(resolved_module_file, submodule_path / module_file)
shutil.copyfile(object_file, dest_file)
shutil.copyfile(needed_file, dest_file)
with open(json_path, "w", encoding="utf-8") as f:
with open(json_file_path, "w", encoding="utf-8") as writer:
Why it matters: Usually legitimate, but worth confirming the paths can't be controlled by untrusted input.
Fix: Confirm which files are written/deleted and that paths cannot be influenced by untrusted input.
The component makes outbound network requests.
import requests
response = requests.post(
urljoin(get_service_root_url(self.base_url) + "/", "load_model"), json={"model": model}, stream=True
)from .requests import RequestState, RequestStatus
from .requests import RequestState, RequestStatus, get_device_and_memory_breakdown, logger
logger.info(f"Paged cache initialized: {self.max_batch_tokens = }, {self.num_sectors = }, {mb_per_sector = }")logger.debug(f"Found a prefix match of {prefix_len} tokens for request {request_id}")logger.debug(f"Evicting {len(evicted_blocks)} cached blocks from allocator {allocator.index}")_, total, reserved, allocated = get_device_and_memory_breakdown()
logger.info(f"Memory available for cache allocation: {available_memory // 1024**2} MB")from .requests import FutureRequestState, logger
logger.warning(f"Processor {class_name} might not be supported by CB.")logger.warning(f"Processor {class_name} isn't supported by CB. Dropping it.")logger.warning(f"Processor {class_name} isn't supported by CB. Kept it because {drop_unsupported = }.")logger.warning(
f"Ignored logit_processor_kwargs: {problematic_keys}. {self.supported_keys = } and {self.ignored_keys = }"
)from .requests import GenerationOutput, RequestState, RequestStatus, logger
logger.info(
f"Rank {global_rank} requested background thread to stop with {status = }. Now {self._local_status = }"
)logger.error(f"A fatal error was already recorded, ignoring later error: {error}")logger.error(f"Error processing new request: {e}", exc_info=True)logger.warning(
f"{msg} Switching from {original_attn_impl} to {target_implem}. If you need to use eager or sdpa, "
"set `auto_switch_to_flash=False` in the continuous batching config." …logger.info(f"{msg} Consider using a flash `attn_implementation` when loading the model.")logger.warning("Manager thread is already running.")logger.warning("\nBatch processor was not initialized.")logger.warning(msg)
logger.info("Continuous batching manager will be kept for next session.")logger.warning(f"Generation thread did not exit after join timeout ({timeout}).")Why it matters: Usually legitimate, but confirm the destinations are expected and no sensitive data leaves.
Fix: Confirm the destination hosts are expected and that no sensitive data is sent off-host.
How attackers abuse these capabilities
Interactive labs on the attack class behind the rules above. They show the technique, not anything found in transformers.
Check your own component
Run the same evidence-backed scan on any MCP server, agent skill, or package.
Scan your own componentHow we determine this: deterministic static analysis (regex + AST), evidence-anchored, no code execution. Methodology →