-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.rs
More file actions
62 lines (50 loc) · 2.11 KB
/
Copy pathbasic_usage.rs
File metadata and controls
62 lines (50 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Example: Basic usage of Rusty Sand library
//!
//! This example demonstrates how to use Rusty Sand as a library
//! to execute a program in a sandboxed environment and analyze the results.
//!
//! Run with: cargo run --example basic_usage
use rusty_sand::{execute_sandboxed, SandboxConfig};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize logging
env_logger::init();
println!("🏖️ Rusty Sand - Basic Usage Example\n");
// Configure the sandbox
let config = SandboxConfig::new()
.with_internet(false) // No internet access (secure default)
.with_timeout(Duration::from_secs(30))
.with_memory_limit(512) // 512 MB memory limit
.with_verbose(true);
println!("Executing notepad.exe in sandbox...\n");
// Execute notepad in the sandbox
let report = execute_sandboxed(
"C:\\Windows\\System32\\notepad.exe",
&[],
config,
)
.await?;
// Analyze the results
println!("\n📊 Analysis Results:");
println!("═══════════════════════════════════════");
println!("Total events captured: {}", report.events.len());
println!("Duration: {} seconds", report.duration_seconds);
println!("Exit code: {}", report.exit_code);
// Get specific event types
let file_events = report.get_file_events();
let network_events = report.get_network_events();
println!("\n📁 File Operations: {}", file_events.len());
for event in file_events.iter().take(5) {
println!(" - {:?}: {}", event.event_type, event.details);
}
println!("\n🌐 Network Activity: {}", network_events.len());
for event in network_events {
println!(" - {:?}: {}", event.event_type, event.details);
}
// Save detailed JSON report
let json_path = std::path::Path::new("./example_report.json");
report.save_json(json_path)?;
println!("\n✅ Full report saved to: {}", json_path.display());
Ok(())
}