Configuration
AI Computer can be configured through client options and environment variables to customize behavior, set resource limits, and control security settings.
Client Configuration
Configure the SandboxClient with options during initialization.
1from ai_computer import SandboxClient
2
3client = SandboxClient(
4 # Resource limits
5 memory_limit="1G",
6 cpu_limit=2,
7 execution_timeout=300,
8 max_processes=10,
9
10 # Network settings
11 allow_network=True,
12 allowed_hosts=["api.example.com"],
13 network_timeout=30,
14
15 # Security options
16 sandbox_user="sandbox",
17 enable_file_access=True,
18 allowed_paths=["/data"],
19
20 # API configuration
21 base_url="https://api.aicomputer.dev",
22 api_key="your-api-key",
23
24 # Advanced options
25 debug=False,
26 log_level="INFO"
27)
Resource Limits
memory_limit
Maximum memory allocation per sandbox.
Type: str, Format: "512M", "1G", etc.
cpu_limit
Number of CPU cores available.
Type: int, Range: 1-4
execution_timeout
Maximum execution time in seconds.
Type: int, Default: 30
max_processes
Maximum number of concurrent processes.
Type: int, Default: 5
Environment Variables
Configure the client using environment variables. These take precedence over programmatic configuration.
Authentication
1# API authentication
2export AICOMPUTER_API_KEY="your-api-key"
3export AICOMPUTER_BASE_URL="https://api.aicomputer.dev"
4
5# Example usage
6client = SandboxClient() # Will use environment variables
Resource Limits
1# Resource configuration
2export AICOMPUTER_MEMORY_LIMIT="1G"
3export AICOMPUTER_CPU_LIMIT="2"
4export AICOMPUTER_TIMEOUT="300"
5export AICOMPUTER_MAX_PROCESSES="10"
Network Settings
1# Network configuration
2export AICOMPUTER_ALLOW_NETWORK="true"
3export AICOMPUTER_ALLOWED_HOSTS="api.example.com,api.other.com"
4export AICOMPUTER_NETWORK_TIMEOUT="30"
Security Configuration
File System Access
Control file system access and permissions.
1client = SandboxClient(
2 # Enable file system access
3 enable_file_access=True,
4
5 # Configure allowed paths
6 allowed_paths=[
7 "/data/input",
8 "/data/output"
9 ],
10
11 # Set file size limits
12 max_file_size="100M",
13
14 # Configure file permissions
15 file_permissions=0o644,
16 directory_permissions=0o755
17)
Network Security
Configure network access and restrictions.
1client = SandboxClient(
2 # Enable network access
3 allow_network=True,
4
5 # Restrict to specific hosts
6 allowed_hosts=[
7 "api.example.com",
8 "storage.example.com"
9 ],
10
11 # Configure timeouts and limits
12 network_timeout=30,
13 max_requests_per_second=10,
14 max_concurrent_connections=5
15)
Logging and Monitoring
Configure logging and monitoring options.
1import logging
2from ai_computer import SandboxClient
3
4# Configure client logging
5client = SandboxClient(
6 debug=True,
7 log_level="DEBUG",
8 log_file="/path/to/aicomputer.log",
9 enable_metrics=True
10)
11
12# Configure Python logging
13logging.basicConfig(
14 level=logging.DEBUG,
15 format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
16)
17
18# Example with custom logger
19logger = logging.getLogger('aicomputer')
20logger.setLevel(logging.DEBUG)
21
22handler = logging.FileHandler('aicomputer.log')
23handler.setFormatter(logging.Formatter(
24 '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
25))
26logger.addHandler(handler)
Best Practices
- Environment Variables: Use environment variables for sensitive configuration like API keys.
- Resource Limits: Set appropriate resource limits based on your workload requirements.
- Security: Follow the principle of least privilege when configuring file and network access.
- Logging: Enable appropriate logging in production for monitoring and debugging.
- Configuration Management: Use configuration management tools or environment-specific config files.