Command-line interface for MockFactory code execution sandbox
Project description
MockFactory CLI
Command-line interface for MockFactory - a secure multi-language code execution sandbox.
Execute code in isolated Docker containers with comprehensive security controls, directly from your terminal.
Features
- Multi-Language Support: Python, JavaScript, PHP, Perl, Go, Shell, HTML
- Secure Execution: All code runs in isolated containers with no network access
- Authentication: Login to access your account and execution history
- Usage Tracking: Monitor your execution limits and tier status
- Beautiful Output: Rich terminal formatting with syntax highlighting
- Easy to Use: Simple commands for quick code execution
Installation
pip install mockfactory-cli
Or install from source:
git clone https://github.com/afterdarksystems/mockfactory-cli.git
cd mockfactory-cli
pip install -e .
Quick Start
Execute code inline
mockfactory run python -c "print('Hello from MockFactory!')"
Execute a file
mockfactory execute script.py
Auto-detect language from file extension
mockfactory execute app.js
mockfactory execute script.php
mockfactory execute program.go
Commands
Authentication
Sign up for a free account
mockfactory signup
Creates a new account with 10 free executions per day.
Login to your account
mockfactory login
Check authentication status
mockfactory status
Logout
mockfactory logout
Code Execution
Run code inline
mockfactory run <language> -c "<code>"
# Examples:
mockfactory run python -c "print('Hello World')"
mockfactory run javascript -c "console.log('Hello World')"
mockfactory run php -c "echo 'Hello World';"
Run code from a file
mockfactory run <language> -f <file>
# Example:
mockfactory run python -f script.py
Execute a file (auto-detect language)
mockfactory execute <file>
# Examples:
mockfactory execute script.py # Python
mockfactory execute app.js # JavaScript
mockfactory execute program.go # Go
mockfactory execute script.sh # Shell
Set execution timeout
mockfactory run python -c "import time; time.sleep(2); print('done')" --timeout 60
Raw output mode
# Useful for piping or scripting
mockfactory run python -c "print('result')" --raw
Usage & Status
Check your usage
mockfactory usage
Shows:
- Current tier (anonymous, free, pro)
- Executions used
- Remaining executions
View configuration
mockfactory config show
Configuration
Set API URL
mockfactory config set api_url https://mockfactory.io
Set timeout
mockfactory config set timeout 60
Reset to defaults
mockfactory config reset
Supported Languages
| Language | Extension | Example |
|---|---|---|
| Python | .py |
mockfactory execute script.py |
| JavaScript | .js |
mockfactory execute app.js |
| PHP | .php |
mockfactory execute script.php |
| Perl | .pl |
mockfactory execute script.pl |
| Go | .go |
mockfactory execute program.go |
| Shell | .sh |
mockfactory execute script.sh |
| HTML | .html |
mockfactory execute page.html |
Usage Tiers
| Tier | Executions | Price | Features |
|---|---|---|---|
| Anonymous | 5/day | Free | No account required |
| Free Account | 10/day | Free | Execution history |
| Pro | Unlimited | $9.99/mo | Priority support |
Sign up for a free account:
mockfactory signup
Upgrade to Pro at mockfactory.io/pricing
Examples
Execute a Python script
mockfactory execute hello.py
Run inline JavaScript
mockfactory run javascript -c "const x = [1,2,3]; console.log(x.reduce((a,b) => a+b, 0))"
Execute with custom timeout
mockfactory execute long_running.py --timeout 120
Check how many runs you have left
mockfactory usage
Pipe output to another command
mockfactory run python -c "print('hello')" --raw | grep hello
Use in shell scripts
#!/bin/bash
result=$(mockfactory run python -c "print(2+2)" --raw)
echo "The answer is: $result"
Mock Resource Management (NEW in v0.2.0)
MockFactory CLI now includes powerful resource management capabilities for creating and managing mock users, groups, containers, networks, and profiles. These features enable comprehensive testing of multi-user applications, access control systems, and containerized environments.
Hierarchical Organization Structure
MockFactory supports a complete organizational hierarchy to mirror real-world enterprise structures:
Organization (acme-corp)
├── Domains (example.com, acme.io)
├── Cloud Environments (dev-cloud, prod-cloud)
│ ├── Users
│ ├── Containers
│ ├── Networks
│ └── Resources
└── Projects (UUID-based)
└── Grouped Resources
Create a complete organizational structure:
# Create an organization
mockfactory organization create acme-corp --description "Acme Corporation" --plan pro
# Create domains for the organization
mockfactory domain create example.com --organization acme-corp --verified
# Create cloud environments
mockfactory cloud create dev-cloud --provider aws --organization acme-corp --region us-east-1
mockfactory cloud create prod-cloud --provider aws --organization acme-corp --region us-west-2
# Create a project to group related resources
mockfactory project create web-app --organization acme-corp --environment production
# Create users within the organizational structure
mockfactory user create john.doe \
--email john@example.com \
--organization acme-corp \
--cloud dev-cloud \
--domain example.com
# Add users to organization with roles
mockfactory organization add-user acme-corp john.doe --role admin
Mock Users
Create and manage mock user accounts for testing:
# Create a mock user
mockfactory user create john.doe --email john@example.com --full-name "John Doe" --role developer
# List all mock users
mockfactory user list
# Filter by role
mockfactory user list --role admin
# Get user details
mockfactory user get john.doe
# Delete a user
mockfactory user delete john.doe --yes
User Roles: user (default), admin, developer
Mock Groups
Organize mock users into groups:
# Create a group
mockfactory group create developers --description "Development team"
# List all groups
mockfactory group list
# Add user to group
mockfactory group add-user developers john.doe
# Remove user from group
mockfactory group remove-user developers john.doe
Mock Containers
Create and manage mock containers with user/group bindings:
# Create a container
mockfactory container create web-app --image nginx --network frontend
# Create container bound to a user
mockfactory container create api --user john.doe --group developers
# List containers
mockfactory container list
# Filter by network or user
mockfactory container list --network frontend
mockfactory container list --user john.doe
# Bind user to existing container
mockfactory container bind-user web-app alice
# Unbind user from container
mockfactory container unbind-user web-app alice
Mock Networks
Create virtual networks for containers:
# Create a network
mockfactory network create frontend --cidr 10.1.0.0/24
# Create isolated network
mockfactory network create backend --cidr 10.2.0.0/24 --isolated
# List networks
mockfactory network list
Mock User Profiles
Create detailed user profiles for testing:
# Create user profile
mockfactory profile create john.doe \
--bio "Senior Developer" \
--avatar "https://example.com/avatar.jpg" \
--preferences '{"theme":"dark","notifications":true}'
# Get user profile
mockfactory profile get john.doe
Use Cases for Mock Resources
Multi-Tenant Testing
# Create tenants
mockfactory user create tenant1 --role admin
mockfactory user create tenant2 --role user
# Create tenant-specific containers
mockfactory container create app-tenant1 --user tenant1
mockfactory container create app-tenant2 --user tenant2
Access Control Testing
# Create user hierarchy
mockfactory group create admins
mockfactory group create users
mockfactory user create admin1 --role admin
mockfactory user create user1 --role user
mockfactory group add-user admins admin1
mockfactory group add-user users user1
# Test with different permission levels
mockfactory container create protected-resource --group admins
Network Isolation Testing
# Create isolated networks
mockfactory network create dmz --cidr 10.10.0.0/24 --isolated
mockfactory network create internal --cidr 10.20.0.0/24 --isolated
# Deploy containers to different networks
mockfactory container create web-server --network dmz
mockfactory container create database --network internal
Integration Testing
# Set up complete test environment
mockfactory user create testuser --email test@example.com
mockfactory group create testers
mockfactory network create testnet --cidr 172.16.0.0/24
mockfactory container create test-env --user testuser --network testnet
mockfactory profile create testuser --bio "Test Account"
Resource Binding
Mock users and groups can be bound to containers and VMs, enabling:
- User-specific environments: Each user gets their own isolated container
- Group-based access: Control which users can access which resources
- Multi-user applications: Test applications with multiple concurrent users
- Permission systems: Verify access control and authorization logic
- Realistic scenarios: Create production-like multi-tenant environments
Mock Mail System
Create and manage complete email testing environments:
# Create a mail server
mockfactory mail-server create smtp-server --protocol smtp --port 587 --tls
# Create mailboxes with standard folders
mockfactory mailbox create john@example.com --user john.doe --quota 1000
# Create a mail client
mockfactory mail-client create client1 --user john.doe --server smtp-server
# Send mock emails
mockfactory mailbox send john@example.com jane@example.com \
--subject "Test Email" --body "Hello Jane!"
# List messages in inbox
mockfactory mailbox list-messages john@example.com --folder inbox
Mock Mail Servers
- Support for SMTP, IMAP, and POP3 protocols
- TLS encryption support
- Configurable host and port settings
Mock Mailboxes
- Standard folders: inbox, outbox, sent, bulk, drafts
- Configurable quota limits
- User binding for multi-user scenarios
- Send and receive mock emails
- Message management and listing
Mock Mail Clients
- Connect to mock mail servers
- Bind to mock users
- Associate with specific mailboxes
Email Testing Use Cases
- Test email sending and receiving workflows
- Verify email notifications in your application
- Test multi-user email scenarios
- Validate email templates and formatting
- Test attachment handling
- Integration testing for email-based features
Mock SMS System
Test SMS-based features and notifications:
# Create an SMS provider
mockfactory sms create-provider twilio-prod --provider twilio
# Create mock phone numbers
mockfactory sms create-number +1234567890 --user john.doe --provider twilio-prod
# Send mock SMS messages
mockfactory sms send +1234567890 +0987654321 --message "Your verification code is 123456"
# List SMS messages
mockfactory sms list-messages --phone-number +1234567890
mockfactory sms list-numbers --user john.doe
SMS Testing Use Cases
- Test SMS verification workflows
- Verify two-factor authentication (2FA)
- Test SMS notifications and alerts
- Validate phone number verification
- Integration testing for SMS-based features
- Test multi-user SMS scenarios
User Registration Workflows
Create complete user registration flows with email and SMS verification:
# Create registration workflow with email verification
mockfactory workflow create-registration signup-flow \
--email-verification \
--mail-server smtp-server
# Create registration workflow with SMS verification
mockfactory workflow create-registration mobile-signup \
--sms-verification \
--sms-provider twilio-prod
# Create workflow with both email and SMS verification
mockfactory workflow create-registration full-signup \
--email-verification \
--sms-verification
# Test the registration workflow
mockfactory workflow test-registration signup-flow \
--username john.doe \
--email john@example.com \
--phone +1234567890
Workflow Testing Use Cases
- Test complete user onboarding flows
- Verify multi-step registration processes
- Test email and SMS verification together
- Validate user activation workflows
- Integration testing for signup features
Mock APIs and Webhooks
Create mock REST APIs, GraphQL endpoints, and webhooks:
# Create a mock REST API
mockfactory api create user-api --type rest --base-url https://api.example.com --auth bearer
# Add endpoints to the API
mockfactory api add-endpoint user-api /users --method GET --status 200
mockfactory api add-endpoint user-api /users --method POST --response '{"id": 1, "name": "John"}'
# Create a webhook
mockfactory api create-webhook payment-hook \
--url https://example.com/webhook \
--events "payment.completed,payment.failed"
# Trigger a webhook event
mockfactory api trigger-webhook payment-hook \
--event "payment.completed" \
--payload '{"amount": 100, "currency": "USD"}'
# List API requests
mockfactory api list-requests user-api --limit 50
API Testing Use Cases
- Test API integrations without external dependencies
- Mock third-party API responses
- Test webhook event handling
- Verify API request/response flows
- Integration testing for API clients
- Test error handling and edge cases
- GraphQL query and mutation testing
Configuration Files
Configuration is stored in ~/.mockfactory/:
config.json- CLI configuration (API URL, timeout, etc.)token- Authentication token (automatically managed)
Security
- All code executes in isolated Docker containers
- No network access for sandbox containers
- Read-only filesystem (except
/tmp) - Resource limits enforced (CPU, memory, time)
- Runs as unprivileged user (
nobody)
Troubleshooting
Authentication errors
If you get authentication errors, try logging out and back in:
mockfactory logout
mockfactory login
Connection errors
Check your API URL configuration:
mockfactory config show
Reset to defaults if needed:
mockfactory config reset
Rate limiting
If you've exceeded your tier's execution limit:
- Wait for the daily reset
- Sign up for a free account (10 runs/day)
- Upgrade to Pro (unlimited)
Aliases
For convenience, you can use the short alias mf:
mf run python -c "print('shorter!')"
mf execute script.py
mf status
Development
Setup development environment
git clone https://github.com/afterdarksystems/mockfactory-cli.git
cd mockfactory-cli
pip install -e ".[dev]"
Run tests
pytest
Code formatting
black .
ruff check .
Links
- Website: mockfactory.io
- Documentation: github.com/afterdarksystems/mockfactory-cli
- Issues: github.com/afterdarksystems/mockfactory-cli/issues
License
MIT License - see LICENSE file for details
Support
For support, contact: support@afterdarksystems.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mockfactory_cli-0.2.0.tar.gz.
File metadata
- Download URL: mockfactory_cli-0.2.0.tar.gz
- Upload date:
- Size: 26.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d181d45d7ef3efc5afe66fd0ea687207f9f22539d22f65cbbd2b1674f713a7be
|
|
| MD5 |
de8c6897599bb28678cfcbddbc32d0e9
|
|
| BLAKE2b-256 |
2818631bdd96f05da7d97008a322066399b24571a2b5a49ca7576dbfe024844a
|
File details
Details for the file mockfactory_cli-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mockfactory_cli-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f77c6575c51096ba34882ce7947f0c2586b1151af723f15e4ebefb74138722c
|
|
| MD5 |
682337eb4642de36e0176862d37c84d4
|
|
| BLAKE2b-256 |
7588f3d3ea31cb75f664ad8cd459ebe86f07e30e99c8e60ee3737ecf97f2fd5e
|