{"id":28192929,"url":"https://github.com/dcspark/shinkai-code-runner","last_synced_at":"2025-05-16T12:16:06.059Z","repository":{"id":246288095,"uuid":"818433169","full_name":"dcSpark/shinkai-code-runner","owner":"dcSpark","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-05T15:20:53.000Z","size":2963,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-10T06:18:50.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcSpark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-21T21:04:40.000Z","updated_at":"2025-05-05T15:20:33.000Z","dependencies_parsed_at":"2024-06-27T02:33:04.167Z","dependency_job_id":"64ee93a6-2089-4850-a3e2-f155403721dd","html_url":"https://github.com/dcSpark/shinkai-code-runner","commit_stats":null,"previous_names":["dcspark/shinkai-tools","dcspark/shinkai-code-runner"],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcSpark%2Fshinkai-code-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcSpark%2Fshinkai-code-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcSpark%2Fshinkai-code-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcSpark%2Fshinkai-code-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcSpark","download_url":"https://codeload.github.com/dcSpark/shinkai-code-runner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527091,"owners_count":22085920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-16T12:15:47.306Z","updated_at":"2025-05-16T12:16:06.052Z","avatar_url":"https://github.com/dcSpark.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Shinkai Tools\n\n[![Mutable.ai Auto Wiki](https://img.shields.io/badge/Auto_Wiki-Mutable.ai-blue)](https://wiki.mutable.ai/dcSpark/shinkai-tools)\n\nShinkai Tools serves as the ecosystem to execute Shinkai tools, provided by the Shinkai team or third-party developers, in a secure environment. It provides a sandboxed space for executing these tools,\nensuring that they run safely and efficiently, while also allowing for seamless integration with Rust code.\n\nThis repository is a comprehensive collection of tools and utilities designed to facilitate the integration of JavaScript and Rust code. It provides a framework for executing Deno scripts within a Rust environment, allowing for seamless communication and data exchange between the two languages.\n\nThe primary components of this repository include:\n- `libs/shinkai-tools-runner` is a Rust library used to execute a tool in a secured and performant Deno environment, providing a safe and efficient way to run tools within the Shinkai ecosystem.\n\n## Documentation\n\nMore In Depth Codebase Documentation (Mutable.ai): [https://wiki.mutable.ai/dcSpark/shinkai-tools](https://wiki.mutable.ai/dcSpark/shinkai-tools)\n\n## Getting started\n\n### Init Typescript side\n\n```\n# In windows admin privileges is required because rquickjs-sys uses a git patch\nnpm ci\nnpx nx run-many -t lint\nnpx nx run-many -t build\nnpx nx run-many -t test\n```\n\n#### Example Usage\n\nTo call a tool from the Rust side, you can use the following example:\n\n```rust\nuse shinkai_tools_runner::{Tool, CodeFiles};\nuse serde_json::json;\n\n#[tokio::main]\nasync fn main() {\n    // Define the inline tool's Deno code\n    let js_code = r#\"\n        function run(configurations, params) {\n            console.log(\"Environment variable:\", Deno.env.get('SHINKAI_MOUNT')); // rw files /path/to/mount1,/path/to/mount2\n            console.log(\"Environment variable:\", Deno.env.get('SHINKAI_ASSETS')); // ro files /path/to/asset1,/path/to/asset2\n            console.log(\"Environment variable:\", Deno.env.get('SHINKAI_HOME')); // rw files /path/to/home\n            console.log(\"Environment variable:\", Deno.env.get('SHINKAI_NODE_LOCATION')); // https://host.docker.internal:9554 (if it's running in docker) or 127.0.0.2:9554 (if it's running in host)\n            return { message: `Echoing: ${params.message}` };\n        }\n    \"#;\n\n    // Set up the code files for the tool\n    // It's important to note that the entrypoint must be the name of the file in the `files` map.\n    // In this case, the entrypoint is `main.ts` and it's mapped to the `js_code` variable.\n    // You can also include other files in the `files` map if your tool needs them.\n    let code_files = CodeFiles {\n        files: std::collections::HashMap::from([(\"main.ts\".to_string(), js_code.to_string())]),\n        entrypoint: \"main.ts\".to_string(),\n    };\n\n    // Create a random file to be used as a mount point. Basically it's a file that could be read/write by the tool\n    let test_file_path = tempfile::NamedTempFile::new().unwrap().into_temp_path();\n    std::fs::create_dir_all(test_file_path.parent().unwrap()).unwrap();\n    println!(\"test file path: {:?}\", test_file_path);\n    std::fs::write(\u0026test_file_path, \"1\").unwrap();\n\n    // Create the tool instance\n    let tool = Tool::new(\n        code_files,\n        json!({}),\n        Some(DenoRunnerOptions {\n            context: ExecutionContext {\n                // Here you specify where the system will store all the files related to execute code\n                storage: execution_storage.into(),\n                // Here you specify the context id, which is a unique identifier for the execution context.\n                // Tools in the same context share the same storage.\n                // It creates a folder with the context id and all the files related to the execution are stored in it.\n                context_id: context_id.clone(),\n                // The execution id is a unique identifier for the execution of the tool\n                // It creates logs for every execution and stores them in the storage folder.\n                execution_id: execution_id.clone(),\n                // The code id is a unique identifier for the code being executed.\n                // Used to identify the tools that's logging in the same execution.\n                code_id: \"js_code1\".into(),\n                // Here you specify the files that will be mounted with read/write permissions into the Deno execution environment.\n                mount_files: vec![test_file_path.to_path_buf().clone()],\n\n                // Here you specify the files that will be mounted with read-only permissions into the Deno execution environment.\n                // assets_files: vec![test_file_path.to_path_buf().clone()],\n                ..Default::default()\n            },\n            ..Default::default()\n        });\n\n    // Run the tool with input data\n    let result = tool.run(None, json!({\"message\": \"Hello, Shinkai!\"}), None).await.unwrap();\n\n    // Print the output\n    println!(\"Tool output: {:?}\", result.data[\"message\"]); // Echoing: ${params.message}\n\n    // After the execution you can find logs in the storage folder, specifically in storage/{context_id}/logs/{execution_id}_....log\n}\n```\n\nThis example demonstrates how to set up and call a Shinkai tool from Rust, including how to pass input data and handle the output.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcspark%2Fshinkai-code-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcspark%2Fshinkai-code-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcspark%2Fshinkai-code-runner/lists"}