Summary
PySyft Datasite/Server allows low-privileged users to submit Python functions for remote execution, but these functions are executed using exec() and eval() without adequate validation or sandboxing.
Once a function is approved through the existing review mechanism, an attacker can execute arbitrary Python code on the server, potentially taking full control of the server environment.
Affected context
This vulnerability appears in PySyft Datasite/Server deployments that:
- Allow users to submit Python functions via
@sy.syft_function()for remote execution - Rely on a human or workflow-based "approval" step without automated security checks
- Execute approved code in the main server process using dynamic evaluation (
exec,eval) - Do not use OS-level or interpreter-level sandboxes, container isolation, or strict policy enforcement
Risk is highest in multi-tenant or shared environments where untrusted or semi-trusted users can upload code.
Exploit preconditions
- Attack surface: Network-accessible PySyft Datasite/Server endpoints that accept user-submitted functions.
- Required access: Low-privileged or regular user ability to submit Python functions for review/approval.
- Trigger point: Execution of an approved
@sy.syft_function()on the server, which runs viaexec()/eval()in the server process. - Why exploitation is possible: The system treats user-supplied code as trusted after approval, but performs no security or policy checks for dangerous operations and runs the code without sandboxing or privilege separation, allowing arbitrary Python execution.
Why this happens
The core issue is a code injection pattern where user-controlled Python source is executed directly with exec() and eval() inside the server process.
This maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), where dynamically built or supplied code is executed without robust validation, constraints, or isolation.
The approval workflow focuses on functional correctness rather than enforcing a strict, machine-verifiable safety policy, and no sandbox or restricted execution environment is used to contain the behavior of approved functions.
Potential impact
- Execution of arbitrary Python code on the server
- Reading, modifying, or deleting files accessible to the server process
- Accessing or exfiltrating sensitive data managed by PySyft or co-located services
- Running system commands or spawning subprocesses (where permitted by the environment)
- Establishing persistence or backdoors on the host
- Using the compromised server as a pivot point for lateral movement within the infrastructure
General mitigation guidance
Mitigation typically focuses on strictly limiting what user-submitted code can do and moving untrusted execution into hardened boundaries:
- Replace generic
exec()/eval()execution of user code with structured, declarative APIs (e.g., whitelisted operations, computation graphs, or domain-specific languages) that do not accept raw Python source. - Introduce a sandboxed execution environment (such as isolated containers, separate processes, or restricted interpreters) with tightly controlled interfaces, resource limits, and no direct access to OS primitives or sensitive files.
- Apply policy-based checks to submitted code or tasks (for example, static filters that reject disallowed modules, attributes, or operations) before approval.
- Enforce least privilege for the execution context so that even if code misbehaves, it has minimal filesystem, network, and process-level permissions.
- Treat code approval as a security decision: incorporate security criteria and, where possible, automated checks to ensure dangerous operations are not allowed.
How teams detect issues like this
Detection can combine code-level review with runtime monitoring:
- Use static analysis or linting rules to flag usage of
exec(),eval(), or similar dynamic execution constructs tied to user input paths. - During code review, look for patterns where user-supplied functions or scripts are accepted and executed without a well-defined sandbox or policy enforcement layer.
- Implement logging around user-submitted function approval and execution, capturing which users submitted which functions and what operations they perform.
- Monitor runtime behavior for unusual file, network, or process activity originating from the worker or server components that handle user functions.
- Enforce CI/CD checks that disallow new dynamic execution entry points unless they are explicitly justified and wrapped in controlled, sandboxed environments.

