Skip to content
Back to search

csharp-runner

fast, secure c# runner

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/sdcb--csharp-runner/badge.svg)](/listings/sdcb--csharp-runner)

HTML

<a href="/listings/sdcb--csharp-runner"><img src="/api/listings/sdcb--csharp-runner/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

**Prerequisites:**

* Docker and Docker Compose

**One-Click Deploy with Docker Compose:**

# Download the docker-compose.yml file
curl -L https://raw.githubusercontent.com/sdcb/csharp-runner/refs/heads/master/docker-compose.yml -o docker-compose.yml

# Start the services in detached mode
docker compose up -d

For Windows:

# Download the docker-compose.yml file
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/sdcb/csharp-runner/refs/heads/master/docker-compose.yml" -OutFile "docker-compose.yml"

# Start the services in detached mode
docker compose -p csharp-runner up -d

Once deployed, open your browser to `http://localhost:5050` to access the web UI.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 219 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # 🚀 C\# Runner
  2. [![.NET 10](https://img.shields.io/badge/.NET-10.0-512BD4.svg)](https://dotnet.microsoft.com/download/dotnet/10.0)
  3. [![Docker-Host](https://img.shields.io/docker/v/sdcb/csharp-runner-host?sort=semver&logo=docker&label=host)](https://hub.docker.com/r/sdcb/csharp-runner-host)
  4. [![Docker-Worker](https://img.shields.io/docker/v/sdcb/csharp-runner-worker?sort=semver&logo=docker&label=worker)](https://hub.docker.com/r/sdcb/csharp-runner-worker)
  5. [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
  6. **English** | [中文](./README_CN.md)
  7. C\# Runner is a high-performance and secure platform for executing C\# code online. It's built on a Host-Worker architecture that isolates code execution in Docker containers and supports dual protocols: HTTP and MCP (Model Context Protocol).
  8. ## ✨ Core Features
  9. - **🔒 Secure & Reliable**
  10. - **Container Isolation**: Untrusted code runs in isolated Docker Worker containers, ensuring host safety.
  11. - **Resource Limits**: Supports CPU, memory, and execution timeout limits to prevent resource abuse.
  12. - **Network Isolation**: Worker containers have restricted network access.
  13. <!-- end list -->
  14. * **Worker Recycling**: Automatically recycles a Worker instance after a configured number of runs to maintain a clean environment.
  15. - **⚡ High-Performance**
  16. - **Worker Warm-up**: Pre-compiles code on startup to ensure optimal performance from the very first run.
  17. - **Load Balancing**: Distributes tasks among multiple Workers using a Round-Robin algorithm.
  18. - **Connection Pooling**: Reuses HttpClient instances to reduce network overhead.
  19. - **🌐 Rich Functionality**
  20. - **Dual Protocol Support**: Offers both an HTTP REST API and an MCP interface.
  21. - **Streaming Output**: Streams code output, results, and errors in real-time using Server-Sent Events (SSE).
  22. - **User-friendly Web UI**: Features a clean code editor with syntax highlighting and `Ctrl+Enter` shortcut for execution.
  23. - **Out-of-the-Box**: Provides a complete Docker Compose solution for one-click deployment.
  24. ## 🚀 Quick Start
  25. **Prerequisites:**
  26. * Docker and Docker Compose
  27. **One-Click Deploy with Docker Compose:**
  28. ```bash
  29. # Download the docker-compose.yml file
  30. curl -L https://raw.githubusercontent.com/sdcb/csharp-runner/refs/heads/master/docker-compose.yml -o docker-compose.yml
  31. # Start the services in detached mode
  32. docker compose up -d
  33. ```
  34. For Windows:
  35. ```bash
  36. # Download the docker-compose.yml file
  37. Invoke-WebRequest -Uri "https://raw.githubusercontent.com/sdcb/csharp-runner/refs/heads/master/docker-compose.yml" -OutFile "docker-compose.yml"
  38. # Start the services in detached mode
  39. docker compose -p csharp-runner up -d
  40. ```
  41. Once deployed, open your browser to `http://localhost:5050` to access the web UI.
  42. ## 🔧 Configuration
  43. ### Docker Compose
  44. The `docker-compose.yml` file defines the Host and Worker services. You can scale the number of Workers by changing `deploy.replicas` and configure Worker behavior via `environment` variables.
  45. ```yml
  46. services:
  47. host:
  48. image: sdcb/csharp-runner-host:latest
  49. container_name: csharp-runner-host
  50. ports:
  51. - "5050:8080"
  52. restart: unless-stopped
  53. worker:
  54. image: sdcb/csharp-runner-worker:latest
  55. environment:
  56. - MaxRuns=2 # Max runs per worker (0=unlimited)
  57. - Register=true # Auto-register to the Host
  58. - RegisterHostUrl=http://host:8080
  59. - WarmUp=false # Enable warm-up (recommended for standalone deployment)
  60. restart: unless-stopped
  61. depends_on:
  62. - host
  63. deploy:
  64. replicas: 3
  65. resources:
  66. limits:
  67. cpus: 0.50
  68. memory: 256M
  69. pids: 32
  70. reservations:
  71. cpus: 0.25
  72. memory: 128M
  73. ```
  74. ### Worker Environment Variables
  75. | Parameter | Description | Default |
  76. | ----------------- | ------------------------------------------------------------------ | --------------- |
  77. | `MaxRuns` | The maximum number of times a Worker can execute code (0=unlimited). | `0` |
  78. | `Register` | Whether to auto-register to the Host service. | `false` |
  79. | `RegisterHostUrl` | The registration URL of the Host service. | `http://host` |
  80. | `ExposedUrl` | The externally exposed URL of the Worker (optional). | `null` |
  81. | `WarmUp` | Whether to perform a warm-up on startup. | `false` |
  82. | `MaxTimeout` | Maximum execution timeout in milliseconds. | `30000` |
  83. ## 📡 API Usage
  84. ### HTTP API (SSE)
  85. Execute code by sending a POST request to `/api/run`. The response is streamed as Server-Sent Events (SSE).
  86. **Request**
  87. ```http
  88. POST /api/run
  89. Content-Type: application/json
  90. {
  91. "code": "Console.WriteLine(\"Hello, World!\"); return 42;",
  92. "timeout": 30000
  93. }
  94. ```
  95. **Response Stream**
  96. ```http
  97. data: {"kind":"stdout","stdOutput":"Hello, World!"}
  98. data: {"kind":"result","result":42}
  99. data: {"kind":"end","elapsed":150,"stdOutput":"Hello, World!","stdError":""}
  100. ```
  101. ### MCP Protocol
  102. The MCP endpoint is at `/mcp` and supports the `run_code` tool.
  103. **Request Example**
  104. ```json
  105. {
  106. "jsonrpc": "2.0",
  107. "method": "tools/call",
  108. "params": {
  109. "name": "run_code",
  110. "arguments": {
  111. "code": "Console.WriteLine(\"Hello from MCP!\");"
  112. }
  113. },
  114. "id": 1
  115. }
  116. ```
  117. ## 🏗️ Architecture & Development Guide
  118. ### System Architecture
  119. - **Host**: Provides the public API and web UI. It receives requests, manages a pool of Workers, and handles load balancing.
  120. - **Worker**: Runs in an isolated sandbox environment, responsible for executing the C\# code and returning the result.
  121. ### Project Structure
  122. ```
  123. src/
  124. ├── Sdcb.CSharpRunner.Host/ # Host Service (ASP.NET Core)
  125. ├── Sdcb.CSharpRunner.Worker/ # Worker Service (Console App)
  126. └── Sdcb.CSharpRunner.Shared/ # Shared Library (DTOs, etc.)
  127. ```
  128. ### Local Development
  129. 1. **Run the Host Service**
  130. ```bash
  131. cd src/Sdcb.CSharpRunner.Host
  132. dotnet run
  133. ```
  134. 2. **Run the Worker Service**
  135. ```bash
  136. cd src/Sdcb.CSharpRunner.Worker
  137. dotnet run
  138. ```
  139. ### Building Custom Images
  140. ```bash
  141. # Build the Host image
  142. dotnet publish ./src/Sdcb.CSharpRunner.Host/Sdcb.CSharpRunner.Host.csproj -c Release /t:PublishContainer /p:ContainerRepository=csharp-runner-host
  143. # Build the Worker image
  144. dotnet publish ./src/Sdcb.CSharpRunner.Worker/Sdcb.CSharpRunner.Worker.csproj -c Release /t:PublishContainer /p:ContainerRepository=csharp-runner-worker
  145. ```
  146. ## 🤝 Contributing
  147. Contributions via Issues and Pull Requests are welcome\! Please follow these steps:
  148. 1. Fork the repository
  149. 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
  150. 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
  151. 4. Push to the branch (`git push origin feature/AmazingFeature`)
  152. 5. Open a Pull Request
  153. ## 📄 License
  154. This project is licensed under the MIT License - see the [LICENSE](https://www.google.com/search?q=LICENSE) file for details.
  155. -----
  156. ⭐ If you find this project helpful, please give it a star\!

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.