The documentation states the following:
Resizing Tables and Columns
The width and height of the datatable is determined by the container element. A scroller is appended to the table body if there are more rows to display. For example, you can restrict the height to 300px by applying CSS styling to the container element.
So, if you set a specific width to the container element, then, my understanding is that the scroller should be appended automatically.
For example:
<div style="width: 300px;">
<!-- lightning:datatable goes here -->
</div>
Tested and Works...
<div class="container" style="width:250px">
<lightning:datatable data="{! v.mydata }"
columns="{! v.mycolumns }"
keyField="id"
onrowselection="{! c.getSelectedName }"/>
</div>