Skip to main content
This guide walks you through creating your first Modal application. You’ll learn how to create a sandbox and call a deployed function.
Before starting, make sure you have installed the SDK and set up authentication.

Create a sandbox

Sandboxes let you run arbitrary code in isolated, containerized environments. Here’s a simple example that creates a sandbox running the cat command:
sandbox_example.py
import modal

# Initialize the Modal client
client = modal.Client()

# Get or create an app
app = client.apps.from_name("my-first-app", create_if_missing=True)

# Use a base image
image = client.images.from_registry("alpine:3.21")

# Create a sandbox
sb = client.sandboxes.create(app, image, command=["cat"])
print(f"Sandbox created: {sb.sandbox_id}")

# Write to stdin and read from stdout
sb.stdin.write_text("Hello from Modal!")
sb.stdin.close()
output = sb.stdout.read_text()
print(f"Output: {output}")

# Clean up
sb.terminate()
Run the script:
python sandbox_example.py

Call a deployed function

You can call Modal Functions that have been deployed using the Python SDK. Here’s how to call a function from each SDK:
call_function.py
import modal

# Initialize the Modal client
client = modal.Client()

# Get a reference to a deployed function
echo = client.functions.from_name(
    "my-app",  # App name
    "echo_string"  # Function name
)

# Call the function with positional arguments
result = echo.remote("Hello world!")
print(result)

# Call the function with keyword arguments
result = echo.remote(s="Hello world!")
print(result)
The Python SDK also lets you define functions using the @app.function() decorator. See the Modal documentation for details.

Key concepts

Apps

Apps are containers for your Modal resources. Every sandbox, function, and resource belongs to an app. You can create apps with from_name() or reference existing ones.

Images

Images define the runtime environment for your code. You can use pre-built images from Docker registries or build custom images with specific dependencies.

Sandboxes

Sandboxes are isolated execution environments where you can run arbitrary commands, execute scripts, and interact with the filesystem. They’re perfect for:
  • Running untrusted code safely
  • Building AI coding agents
  • Processing data in isolated environments
  • Testing code in different environments

Functions

Functions are Python callables deployed on Modal that you can invoke from any SDK. They automatically handle serialization, execution, and result retrieval.

Next steps

Explore examples

Browse example applications and use cases

API reference

Dive into the complete API documentation

User guide

Learn best practices and advanced features

Join the community

Get help and share your projects on Slack

Build docs developers (and LLMs) love