Skip to content

itisrohit/Valkode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Valkode πŸš€

A blazingly fast, security-focused multi-language code execution engine built on a next-generation hybrid architecture.

It leverages Bun + Hono for ultra-low-latency API performance while separating execution concerns for maximum efficiency and control.


πŸ”₯ Why Valkode?

  • ⚑ Sub-millisecond execution – 1ms warm execution via optimized worker pools
  • 🐍 Python daemon architecture – Persistent Python workers for lightning-fast execution
  • πŸ”’ V8-Level Isolation – Sandbox JavaScript with zero access to Node.js internals
  • 🧠 Hybrid Engine – Bun for APIs, Node.js for secure execution, Python daemons for speed
  • πŸ“ˆ Infinite Scalability – Smart queuing + auto-scaling workers (2-8 workers)
  • πŸ›‘οΈ Enterprise-Ready – Multi-layer sandboxing, validation, and fault tolerance
  • βœ… 320+ req/sec – Proven high-throughput performance under stress testing

βš™οΈ Performance Benchmarks

Language Cold Start Warm Execution Throughput Security
JavaScript 24-35ms 1ms 1862 req/s V8 Isolation
TypeScript 45ms 3-6ms 213 req/s V8 Isolation
Python 12ms 1ms 320 req/s Daemon Pool

Benchmarks from stress testing with 20 concurrent requests


🧱 Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Bun + Hono   │────│ Process Pool      │────│ isolated-vm     β”‚
β”‚ (API Layer)  β”‚    β”‚ Auto-Scaling      β”‚    β”‚ V8 Sandbox      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   ⚑ Ultra Fast        πŸ”„ Smart Queuing       πŸ”’ Perfect Isolation

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Universal    │────│ Python Daemon     │────│ Persistent      β”‚
β”‚ Runner       β”‚    β”‚ Pool              β”‚    β”‚ Workers         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   🌐 Multi-lang       🐍 Lightning Fast      ⚑ Sub-ms execution

🧠 Smart Worker Management

  • JavaScript Pool: 2–8 workers with dynamic scaling
  • Python Daemon Pool: Persistent workers for zero cold starts
  • Load-balanced request distribution with intelligent queuing
  • Fault tolerance via auto-healing and graceful shutdowns
  • Memory-efficient idle worker cleanup

✨ Core Features

  • πŸ”’ V8-Level Sandboxing – Total isolation from require, process, global, etc.
  • ⚑ Sub-millisecond Performance – Warm starts in 1ms for JS/Python
  • 🐍 Python Daemon Architecture – Persistent workers eliminate cold starts
  • πŸ›‘οΈ Layered Security – V8, subprocess, and input validations
  • 🌐 RESTful API – Minimal, production-ready endpoints
  • ⏱️ Smart Timeout Handling – Queue-aware and configurable
  • πŸ“Š Real-time Metrics – Monitor worker states and performance
  • πŸ§ͺ Full Test Coverage – 30 tests, 178 assertions, 100% pass rate
  • πŸ” Zero Downtime – Graceful shutdowns and resilient queues
  • πŸš€ Stress Tested – 320+ req/sec with 100% success rate

🌍 Supported Languages

Language Aliases Security Performance Concurrency Status
JavaScript javascript, js πŸ”’ V8 Isolation ⚑ 1ms 1862 req/s βœ… Stable
TypeScript typescript, ts πŸ”’ V8 Isolation ⚑ 3-6ms 213 req/s βœ… Stable
Python python, py 🐍 Daemon Pool ⚑ 1ms 320 req/s βœ… Stable

πŸš€ Quick Start

πŸ“¦ Prerequisites

  • Bun v1.2+
  • Node.js v20+ (required for isolated-vm)
  • Python 3.11+ (for Python execution support)

πŸ§‘β€πŸ’» Installation

git clone https://github.com/itisrohit/valkode.git
cd valkode
bun install

# Install worker dependencies
cd scripts && npm install && cd ..

▢️ Start the Server

bun run src/server.ts

You'll see:

πŸš€ Initializing JavaScript process pool with 2 workers...
πŸš€ Initializing python daemon pool with 2 workers...
βœ… Process pool initialized with 2 workers
πŸ”₯ python pool warmed up
βœ… Python runner ready
πŸš€ Valkode server listening on http://localhost:3000

πŸ“‘ API Endpoints

Health Check

GET /api/v1/health

Response:

{
  "success": true,
  "data": {
    "status": "ok",
    "processPool": {
      "totalWorkers": 2,
      "busyWorkers": 0,
      "idleWorkers": 2,
      "pendingRequests": 0
    },
    "runners": {
      "python": {
        "available": true,
        "totalWorkers": 4,
        "successRate": 100
      }
    }
  }
}

Supported Languages

GET /api/v1/languages

Response:

{
  "success": true,
  "data": {
    "languages": ["javascript", "js", "typescript", "ts", "python", "py"]
  }
}

Execute Code

POST /api/v1/execute

Request:

{
  "code": "console.log('Hello World!');",
  "language": "javascript",
  "timeout": 5000
}

Response:

{
  "success": true,
  "data": {
    "success": true,
    "output": "Hello World!",
    "executionTime": 1
  }
}

πŸ’» Code Execution Examples

JavaScript

curl -X POST http://localhost:3000/api/v1/execute \
  -H "Content-Type: application/json" \
  -d '{"code": "console.log(2 + 2);", "language": "javascript"}'

TypeScript

curl -X POST http://localhost:3000/api/v1/execute \
  -H "Content-Type: application/json" \
  -d '{"code": "const msg: string = \"Hello\"; console.log(msg);", "language": "typescript"}'

Python

curl -X POST http://localhost:3000/api/v1/execute \
  -H "Content-Type: application/json" \
  -d '{"code": "print(\"Hello from Python daemon!\")", "language": "python"}'

πŸ” Security Overview

JavaScript / TypeScript

  • Complete V8 isolation using isolated-vm
  • require, process, global, eval – all blocked
  • No file system or network access
  • Memory-limited execution contexts

Python

  • Persistent daemon workers with controlled environments
  • Input validation and sanitization
  • Isolated execution contexts per request
  • Resource limiting and timeout controls

🧩 Configurable Settings

// JavaScript Process Pool
{
  minWorkers: 2,
  maxWorkers: 8,
  workerIdleTimeout: 30000,
  maxQueueSize: 100
}

// Python Daemon Pool  
{
  poolSize: 2,
  warmupEnabled: true,
  persistentWorkers: true
}

Default timeout: 5000ms
Memory limit: 128MB per worker
Default port: 3000


πŸ“ Project Structure

src/
β”œβ”€β”€ api/            β†’ REST endpoints (health, execute, languages)
β”œβ”€β”€ engine/         β†’ Core execution logic & sandbox
β”œβ”€β”€ runners/        β†’ Language-specific execution handlers
β”œβ”€β”€ types/          β†’ TypeScript type definitions
β”œβ”€β”€ utils/          β†’ Process pools & worker management
scripts/            β†’ Isolated VM worker scripts
tests/              β†’ Comprehensive test suite (30 tests)
β”œβ”€β”€ sandbox.test.ts β†’ Core functionality tests
β”œβ”€β”€ api.test.ts     β†’ API performance tests  
└── benchmarks.test.ts β†’ Performance benchmarks

πŸ§ͺ Testing & Monitoring

Run Tests

# Run all tests
bun test

# Run CI simulation (full pipeline)
./scripts/test-ci.sh

Test Coverage:

  • βœ… 30 tests passing
  • βœ… 178 assertions
  • βœ… Core functionality, API performance, benchmarks
  • βœ… Stress testing (320+ req/sec throughput)
  • βœ… Concurrent execution (20 simultaneous requests)

Monitor Real-time Performance

# Monitor process pool status
watch -n 1 'curl -s http://localhost:3000/api/v1/health | jq .data.processPool'

# Monitor Python daemon status
watch -n 1 'curl -s http://localhost:3000/api/v1/health | jq .data.runners.python'

Load Testing

# High-throughput testing
ab -n 1000 -c 20 -p post_data.json -T application/json \
   http://localhost:3000/api/v1/execute

πŸ—ΊοΈ Roadmap

βœ… Phase 2A (Complete)

  • βœ… Process pool with auto-scaling (2-8 workers)
  • βœ… V8 isolation + intelligent queuing
  • βœ… Python daemon architecture for sub-ms execution
  • βœ… Multi-language support (JS, TS, Python)
  • βœ… Comprehensive testing suite (30 tests)
  • βœ… Production-ready performance (320+ req/sec)

πŸš€ Phase 2B (In Progress)

  • πŸ”„ Go language support
  • πŸ”„ WebAssembly (WASM) integration
  • πŸ”„ Enhanced monitoring & metrics

πŸ¦€ Phase 3

  • Rust execution via WASM
  • C/C++ support via WASM
  • Advanced resource limiting

🌐 Phase 4

  • WebSocket support for real-time execution
  • Multi-file & package execution
  • Redis-powered distributed worker pools
  • Horizontal scaling capabilities

🎯 Phase 5

  • Complete WASM ecosystem (Ruby, Java via GraalVM)
  • Plugin architecture for custom languages
  • Advanced security sandboxing
  • Enterprise deployment tools

🀝 Contributing

git checkout -b feature/your-feature
bun test                    # Ensure all tests pass
./scripts/test-ci.sh       # Run full CI simulation
git commit -m "feat: add awesome feature"
git push origin feature/your-feature

Contribution Guidelines:

  • πŸ’― Maintain test coverage (currently 30 tests, 178 assertions)
  • πŸ§ͺ Security-first development
  • 🧠 Smart worker pool behavior
  • πŸ“ˆ Performance regression testing
  • πŸ“š Update documentation and benchmarks

πŸ™ Acknowledgments

  • Bun – Ultra-fast JavaScript runtime
  • isolated-vm – V8 isolation
  • Hono – Fast web framework
  • Open Source Security Community

Built with ❀️ by Rohit Kumar

⭐ Star this repo if you liked it!


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published