
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
trpc.group/trpc-go/trpc-agent-go/examples/codeexecution
Advanced tools
This example demonstrates how to use the code execution capabilities with both LocalCodeExecutor and ContainerCodeExecutor implementations.
The code execution system allows you to execute code snippets in various programming languages (Python, Bash) either locally or in isolated Docker containers.
Executes code directly on the local machine. Suitable for trusted environments.
Executes code in isolated Docker containers. Provides better security and isolation.
| Variable | Description | Default Value |
|---|---|---|
OPENAI_API_KEY | API key for the model service (required, automatically read by OpenAI SDK) | `` |
OPENAI_BASE_URL | Base URL for the model API endpoint (automatically read by OpenAI SDK) | https://api.openai.com/v1 |
Note: OPENAI_API_KEY and OPENAI_BASE_URL are automatically read by the OpenAI SDK. You don't need to manually read these environment variables in your code. The SDK handles this automatically when creating the client.
| Argument | Description | Default Value |
|---|---|---|
-model | Name of the model to use | deepseek-chat |
cd examples/codeexecution
export OPENAI_API_KEY="your-api-key-here"
go run main.go
export OPENAI_API_KEY="your-api-key"
export OPENAI_BASE_URL="https://api.deepseek.com/v1"
go run main.go -model deepseek-chat
When you run the example, you might see output like:
Creating LLMAgent with configuration:
- Model Name: deepseek-chat
- OpenAI SDK will automatically read OPENAI_API_KEY and OPENAI_BASE_URL from environment
=== LLMAgent Execution ===
Processing events from LLMAgent:
--- Event xxx ---
.......
--- Event 328 ---
ID: 30641681-7f0f-46cc-b992-003458af0c3d
Author: data_science_agent
InvocationID: invocation-7d8497e5-d9d0-462c-bee0-4be82e8924a2
Object:
Message Content: I'll analyze the given sample data (5, 12, 8, 15, 7, 9, 11) using Python's standard library functions. Here's the complete analysis in a single code block:
```python
import statistics
# Data processing and analysis
data = [5, 12, 8, 15, 7, 9, 11]
sorted_data = sorted(data)
length = len(data)
minimum = min(data)
maximum = max(data)
mean = statistics.mean(data)
median = statistics.median(data)
stdev = statistics.stdev(data) if len(data) > 1 else 0
variance = statistics.variance(data) if len(data) > 1 else 0
# Output results
print(f"Original data: {data}")
print(f"Sorted data: {sorted_data}")
print(f"Count: {length}")
print(f"Minimum: {minimum}")
print(f"Maximum: {maximum}")
print(f"Mean: {mean:.2f}")
print(f"Median: {median}")
print(f"Standard deviation: {stdev:.2f}")
print(f"Variance: {variance:.2f}")
This code will:
The analysis includes both measures of central tendency (mean, median) and measures of dispersion (standard deviation, variance), along with basic data characteristics like count, min, and max values. Token Usage - Prompt: 860, Completion: 320, Total: 1180 Done: true
--- Event 329 --- ID: 815e45db-7ae0-48c2-a330-da924d2a8122 Author: data_science_agent InvocationID: invocation-7d8497e5-d9d0-462c-bee0-4be82e8924a2 Object: Message Content: Code execution result: Original data: [5, 12, 8, 15, 7, 9, 11] Sorted data: [5, 7, 8, 9, 11, 12, 15] Count: 7 Minimum: 5 Maximum: 15 Mean: 9.57 Median: 9 Standard deviation: 3.36 Variance: 11.29
Done: false
--- Event 330 --- ID: 9c14d605-3e9b-40f8-9c61-42d901ee9b4a Author: data_science_agent InvocationID: invocation-7d8497e5-d9d0-462c-bee0-4be82e8924a2 Object: runner.completion Done: true
=== Execution Complete ===
### Security Considerations
When using code execution, especially with user-provided code:
1. **Container Isolation**: Use `ContainerCodeExecutor` for better security isolation
2. **Timeouts**: Always set reasonable timeouts to prevent infinite loops
3. **Resource Limits**: Consider Docker resource limits for container execution
4. **Input Validation**: Validate code input before execution
5. **Network Isolation**: Containers run with limited network access
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.