| from bee.self_coding import BeeSelfCodingEngine | |
| import json | |
| coding = BeeSelfCodingEngine(max_iterations=3) | |
| # Test 1: Sandbox execution of valid code | |
| print('=== BEE SELF-CODING: SANDBOX EXECUTION ===') | |
| code = ''' | |
| def fast_fibonacci(n): | |
| if n <= 1: | |
| return n | |
| a, b = 0, 1 | |
| for _ in range(n - 1): | |
| a, b = b, a + b | |
| return b | |
| result = fast_fibonacci(30) | |
| print(f'Fibonacci(30) = {result}') | |
| ''' | |
| result = coding._run_in_sandbox(code) | |
| print(json.dumps(result, indent=2)) | |
| # Test 2: AST security filter | |
| print() | |
| print('=== SECURITY TEST: FORBIDDEN IMPORT ===') | |
| try: | |
| coding._sanitize_code('import os; os.system("rm -rf /")') | |
| print('SECURITY FAIL: Unsafe code accepted') | |
| except ValueError as e: | |
| print(f'SECURITY PASS: {e}') | |
| # Test 3: Forbidden function call | |
| print() | |
| print('=== SECURITY TEST: FORBIDDEN FUNCTION ===') | |
| try: | |
| coding._sanitize_code('eval("1+1")') | |
| print('SECURITY FAIL: eval accepted') | |
| except ValueError as e: | |
| print(f'SECURITY PASS: {e}') | |