MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / wrap_command_with_bubblewrap

Function wrap_command_with_bubblewrap

src/execution/mod.rs:42–97  ·  view source on GitHub ↗

Wrap a command with bubblewrap sandbox to isolate network access Returns true if bubblewrap was applied, false otherwise

(
    binary: &Path,
    extra_args: &Vec<S>,
    extra_envs: &Vec<(S, S)>,
    asan_options: &str,
    fuzzer_args: &[String],
)

Source from the content-addressed store, hash-verified

40/// Wrap a command with bubblewrap sandbox to isolate network access
41/// Returns true if bubblewrap was applied, false otherwise
42fn wrap_command_with_bubblewrap<S: AsRef<OsStr> + Debug>(
43 binary: &Path,
44 extra_args: &Vec<S>,
45 extra_envs: &Vec<(S, S)>,
46 asan_options: &str,
47 fuzzer_args: &[String],
48) -> Command {
49
50 // Reset the command to use bwrap as the main executable
51 let mut cmd = Command::new("bwrap");
52
53
54 // Mount essential system directories as read-only
55 cmd.arg("--ro-bind").arg("/").arg("/");
56 cmd.arg("--proc").arg("/proc");
57 cmd.arg("--dev").arg("/dev");
58 cmd.arg("--tmpfs").arg("/tmp");
59
60
61 // Deny network access
62 cmd.arg("--unshare-net");
63 //cmd.arg("--unshare-pid");
64 cmd.arg("--die-with-parent");
65 cmd.arg("--new-session");
66
67 // Mount the working directory with read-write access
68 //let workspace_root = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("/"));
69 cmd.arg("--bind").arg(Deopt::get_crate_dir().unwrap()).arg(Deopt::get_crate_dir().unwrap());
70
71 // Pass through environment variables
72 for (key, val) in extra_envs {
73 cmd.arg("--setenv")
74 .arg(key.as_ref())
75 .arg(val.as_ref());
76 }
77
78 // Set ASAN_OPTIONS
79 cmd.arg("--setenv").arg("ASAN_OPTIONS").arg(asan_options);
80 cmd.arg("stdbuf").arg("-oL").arg("-eL");
81
82 // Add the actual binary to execute
83 cmd.arg(binary);
84
85 // Add fuzzer-specific arguments
86 for arg in fuzzer_args {
87 cmd.arg(arg);
88 }
89
90 // Add extra arguments
91 for arg in extra_args {
92 cmd.arg(arg.as_ref());
93 }
94
95 log::trace!("Running with bubblewrap sandbox: {:?}", cmd);
96 return cmd;
97}
98
99#[derive(Debug, Clone, clap::ValueEnum, PartialEq)]

Callers 2

spawnMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected