Paper · 2507.00485 · IJCAI · 2025
PNAct: Crafting Backdoor Attacks in Safe Reinforcement Learning
Ling Wang, Weiran Guo, Guanjun Liu, Ziyuan Zhou
arXiv · PDF · Open in the Atlas
Code that ran
3 of 3 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 1 failure of our instrument; 0 no recorded run), measured 2026-11-23; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.
- 2 ran with no instrument failure
0 honoured the contract we drafted, 0 violated it, 2 have no contract verdict
- 1 ran where Syntology's instrument failed
failures of Syntology's instrument, not of the code: 1 where our contract draft was wrong, 0 where the contract check could not run
- 0 have no recorded run
- 0 of those that ran constructed an object rather than computing a result
an executed sample whose run returned an instance of its own class (fixture_out_type equals the entry name): the run built an object and did not compute a result
- 0 are pointer only: the body is not served under this paper's link
"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2507.00485.json · badge: /api/ran/2507.00485.svg
Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.
| Repository | Role | Ran |
|---|
| azure-123/PNAct |
community Papers with Code archive |
3 ran · 0 no recorded run |
| Function | Status | Where it lives |
|---|
| Actor |
Ran ran on a synthesized input |
azure-123/PNAct/safepo/common/model.py code served (permissive licence) · get_code("832a4c764134d431") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Normal. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import numpy as np
import torch
import torch.nn as nn
from torch.distributions import Normal
def build_mlp_network(sizes):
"""
Build a multi-layer perceptron (MLP) neural network.
This function constructs an MLP network with the specified layer sizes and activation functions.
Args:
sizes (list of int): List of integers representing the sizes of each layer in the network.
Returns:
nn.Sequential: An instance of PyTorch's Sequential module representing the constructed MLP.
"""
layers = list()
for j in range(len(sizes) - 1):
act = nn.Tanh if j < len(sizes) - 2 else nn.Identity
affine_layer = nn.Linear(sizes[j], sizes[j + 1])
nn.init.kaiming_uniform_(affine_layer.weight, a=np.sqrt(5))
layers += [affine_layer, act()]
return nn.Sequential(*layers)
class Actor(nn.Module):
"""
Actor network for policy-based reinforcement learning.
This class represents an actor network that outputs a distribution over actions given observations.
Args:
obs_dim (int): Dimensionality of the observation space.
act_dim (int): Dimensionality of the action space.
Attributes:
mean (nn.Sequential): MLP network representing the mean of the action distribution.
log_std (nn.Parameter): Learnable parameter representing the log standard deviation of the action distribution.
Example:
obs_dim = 10
act_dim = 2
actor = Actor(obs_dim, act_dim)
observation = torch.randn(1, obs_dim)
action_distribution = actor(observation)
"""
def __init__(self, obs_dim: int, act_dim: int, hidden_sizes: list=[64, 64]):
super().__init__()
self.mean = build_mlp_network([obs_dim] + hidden_sizes + [act_dim])
self.log_std = nn.Parameter(torch.zeros(act_dim), requires_grad=True)
def forward(self, obs: torch.Tensor):
mean = self.mean(obs)
std = torch.exp(self.log_std)
return Normal(mean, std)
INIT_ARGS = {
'obs_dim': 4,
'act_dim': 3,
'hidden_sizes': [8, 8]
}
ARGS = {
'obs': torch.randn(2, 4)
}
actor = Actor(**INIT_ARGS)
distribution = actor(**ARGS)
print(f"Distribution mean shape: {distribution.mean.shape}")
print(f"Distribution stddev shape: {distribution.stddev.shape}")
print(f"Sample shape: {distribution.sample().shape}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Normal — a Normal output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Normal output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| PNAct |
Ran ran on a synthesized input |
azure-123/PNAct/safepo/common/model.py code served (permissive licence) · get_code("0067336dfb17262d") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import numpy as np
import torch
import torch.nn as nn
from torch.distributions import Normal
class Actor(nn.Module):
def __init__(self, obs_dim: int, act_dim: int, hidden_sizes: list=[64, 64]):
super().__init__()
self.mean = build_mlp_network([obs_dim] + hidden_sizes + [act_dim])
self.log_std = nn.Parameter(torch.zeros(act_dim), requires_grad=True)
def forward(self, obs: torch.Tensor):
mean = self.mean(obs)
std = torch.exp(self.log_std)
return Normal(mean, std)
def build_mlp_network(sizes):
layers = list()
for j in range(len(sizes) - 1):
act = nn.Tanh if j < len(sizes) - 2 else nn.Identity
affine_layer = nn.Linear(sizes[j], sizes[j + 1])
nn.init.kaiming_uniform_(affine_layer.weight, a=np.sqrt(5))
layers += [affine_layer, act()]
return nn.Sequential(*layers)
class PNAct(nn.Module):
def __init__(self, obs_dim, act_dim, hidden_sizes: list=[64, 64]):
super().__init__()
self.network = Actor(obs_dim, act_dim, hidden_sizes)
def get_action(self, obs, deterministic=True):
dist = self.network(obs)
if deterministic:
action = dist.mean
else:
action = dist.rsample()
log_prob = dist.log_prob(action).sum(axis=-1)
return (action, log_prob)
INIT_ARGS = {
'obs_dim': 4,
'act_dim': 3,
'hidden_sizes': [8, 8]
}
ARGS = {
'obs': torch.randn(2, 4),
'deterministic': True
}
METHOD = 'get_action'
if __name__ == '__main__':
model = PNAct(**INIT_ARGS)
result = model.get_action(**ARGS)
print(f"Action shape: {result[0].shape}")
print(f"Log prob shape: {result[1].shape}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type tuple — a tuple output has no array shape of its own; none is stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| build_mlp_network |
Ran ran; our contract draft was wrong, not the code |
azure-123/PNAct/safepo/common/model.py code served (permissive licence) · get_code("66df63cc965e3218") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Sequential. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
import numpy as np
torch.manual_seed(0)
# The function build_mlp_network takes a list of integers representing layer sizes
# and constructs an MLP with Linear layers and Tanh activations (except the last layer uses Identity)
# Create a simple MLP architecture: input_size -> hidden1 -> hidden2 -> output_size
sizes = [4, 8, 6, 2]
ARGS = {
"sizes": sizes
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Sequential — a Sequential output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Sequential output the recorded ndim 1 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
Also present in other papers' code
Of 3 samples lifted from this paper's linked repositories, 3 carry a function identity and 0 do not. Of the 3 distinct functions with an identity, 1 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 1 later) and 2 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).
Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.
| Function | Also present in | Earliest-dated | Others named |
|---|
| build_mlp_network brick of this paper's assembly: helper |
1 other paper 1 later |
2604.19737 (2026-04) Safe Continual Reinforcement Learning in Non-stationary Environments |
|
Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.
Repositories linked to this paper
Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.
Abstract
Reinforcement Learning (RL) is widely used in tasks where agents interact with an environment to maximize rewards. Building on this foundation, Safe Reinforcement Learning (Safe RL) incorporates a cost metric alongside the reward metric, ensuring that agents adhere to safety constraints during decision-making. In this paper, we identify that Safe RL is vulnerable to backdoor attacks, which can manipulate agents into performing unsafe actions. First, we introduce the relevant concepts and evaluation metrics for backdoor attacks in Safe RL. It is the first attack framework in the Safe RL field that involves both Positive and Negative Action sample (PNAct) is to implant backdoors, where positive action samples provide reference actions and negative action samples indicate actions to be avoided. We theoretically point out the properties of PNAct and design an attack algorithm. Finally, we conduct experiments to evaluate the effectiveness of our proposed backdoor attack framework, evaluating it with the established metrics. This paper highlights the potential risks associated with Safe RL and underscores the feasibility of such attacks. Our code and supplementary material are available at https://github.com/azure-123/PNAct.
For agents
The same record, over MCP at https://syntology.ai/mcp:
get_harvested_code_for_paper("2507.00485")
get_code_for_paper("2507.00485")
have("2507.00485")
The run record, dated, one paper per request, free:
curl https://syntology.ai/api/ran/2507.00485.json
A badge for a README (the split and the date, never a ratio):
[](https://syntology.ai/paper/2507.00485)
Connect an agent — have() is free.