use praisonai::{Agent, tool};// Define a code execution tool#[tool(description = "Execute Python code and return the result")]async fn run_python(code: String) -> String { // Execute code in sandbox execute_python_sandboxed(&code).await}// Create agent with code execution toollet agent = Agent::new() .name("Coder") .instructions("Write and execute code to solve problems. Use the run_python tool.") .tool(run_python) .build()?;let response = agent.chat("Calculate the first 10 Fibonacci numbers").await?;// Agent writes Python code and executes it via the tool
2
Safe Code Sandbox
use praisonai::tool;#[tool(description = "Execute JavaScript code safely")]async fn run_js(code: String) -> String { // Use sandboxed environment with timeout sandbox::execute_with_timeout( &code, std::time::Duration::from_secs(10) ).await}